Re: Make a Parameter CONST?
David,
Yes, this is exactly what I was getting at. To me it's a safety issue more
then anything. I want to avoid introducing subtle bugs that are hard to
find. If you pass an object to someone elses method (say a 3rd Party), you
don't know what they are doing with your object and therefore you can't
guarntee the state of the object you passed in (unless you work around this
issue) once the method returns.
Brien King
"david" <david@woofix.l ocal.dom> wrote in message
news:slrndio3ot .edn.david@loca lhost.localdoma in...[color=blue]
> On 2005-09-17, m.posseth <michelp@nohaus ystems.nl> wrote:[color=green]
>> after rethinking ,,, i provided a workaround but it is absolutely
>> useless
>>
>> why the $##$$# would you do that if you could just as easily use a local
>> (
>> in the same class as the method ) contstant value
>>
>> maybe we should ask you what is your situation in wich you think this is
>> needed ???
>>
>> as i said i would not pass a contstant value at all to a parameter , i
>> would
>> make it a class construct parameter and call it with a read only property
>> in
>> the method itself[/color]
>
> You're missing the point. What the OP wants is to pass reference types
> to a method and ensure that the method won't change the contents of the
> passed object. It would look something like this...
>
> Public Sub Foo(ByConst list As ArrayList)
>
> Console.Writeli ne(list(0)) ' This is OK
> list(0) = "Hello" ' This would be a compile error
>
>
> Because the list parameter is declared const, the Foo method can't
> change the contents. This is a very common construct in C++, but
> isn't supported in the CLR or the Framework.
>
>
>
>
>
>
>[color=green]
>>
>> regards
>>
>> Michel Posseth [MCP]
>>
>>
>>
>>
>> "Brien King" <spammehere@arc aderestoration. com> wrote in message
>> news:erx4YvyuFH A.2008@TK2MSFTN GP10.phx.gbl...[color=darkred]
>>> If I have a parameter that has an Object type (as opposed to something
>>> like a string), can I make that parameter a CONST?
>>>
>>> Right now, if you pass an object into a sub/function, that sub/function
>>> can modify the object no matter how it's defined (ByVal or ByRef).
>>>
>>> In some cases, I want to make sure that you cannot modify the object.
>>> Is
>>> there a way to do that in VS2003 or the up comming VS2005?
>>>
>>>
>>> Thanks,
>>>
>>>
>>> Brien King
>>>[/color]
>>
>>[/color][/color]
David,
Yes, this is exactly what I was getting at. To me it's a safety issue more
then anything. I want to avoid introducing subtle bugs that are hard to
find. If you pass an object to someone elses method (say a 3rd Party), you
don't know what they are doing with your object and therefore you can't
guarntee the state of the object you passed in (unless you work around this
issue) once the method returns.
Brien King
"david" <david@woofix.l ocal.dom> wrote in message
news:slrndio3ot .edn.david@loca lhost.localdoma in...[color=blue]
> On 2005-09-17, m.posseth <michelp@nohaus ystems.nl> wrote:[color=green]
>> after rethinking ,,, i provided a workaround but it is absolutely
>> useless
>>
>> why the $##$$# would you do that if you could just as easily use a local
>> (
>> in the same class as the method ) contstant value
>>
>> maybe we should ask you what is your situation in wich you think this is
>> needed ???
>>
>> as i said i would not pass a contstant value at all to a parameter , i
>> would
>> make it a class construct parameter and call it with a read only property
>> in
>> the method itself[/color]
>
> You're missing the point. What the OP wants is to pass reference types
> to a method and ensure that the method won't change the contents of the
> passed object. It would look something like this...
>
> Public Sub Foo(ByConst list As ArrayList)
>
> Console.Writeli ne(list(0)) ' This is OK
> list(0) = "Hello" ' This would be a compile error
>
>
> Because the list parameter is declared const, the Foo method can't
> change the contents. This is a very common construct in C++, but
> isn't supported in the CLR or the Framework.
>
>
>
>
>
>
>[color=green]
>>
>> regards
>>
>> Michel Posseth [MCP]
>>
>>
>>
>>
>> "Brien King" <spammehere@arc aderestoration. com> wrote in message
>> news:erx4YvyuFH A.2008@TK2MSFTN GP10.phx.gbl...[color=darkred]
>>> If I have a parameter that has an Object type (as opposed to something
>>> like a string), can I make that parameter a CONST?
>>>
>>> Right now, if you pass an object into a sub/function, that sub/function
>>> can modify the object no matter how it's defined (ByVal or ByRef).
>>>
>>> In some cases, I want to make sure that you cannot modify the object.
>>> Is
>>> there a way to do that in VS2003 or the up comming VS2005?
>>>
>>>
>>> Thanks,
>>>
>>>
>>> Brien King
>>>[/color]
>>
>>[/color][/color]
Comment