Sam Gentile [mailto:[EMAIL PROTECTED]] wrote:

> I haven't found this in C#. Does C# have the equivalent of
> C++'s const parameters or const methods? This is common in
> C++: void Foo(const string& str)
>
> Even with MC++, it appears that although const parameters can
> be used in the methods of a managed class, methods themselves
> cannot be defined as const.

No, I don't believe there's any CIL level concept of const params. I guess
this is in part due to the fact that unless params are explicitly marked as
by reference with the "ref" or "out" keywords, they're by value and you can
never hurt the caller by modifying one of them anyway. There is no CIL level
concept of a const method either AFAIK.

I suppose a specific language implementation could support such concepts
though and handle it at compile time, making sure your don't modify
paramaters for the former and making sure you don't write to any fields
directly or indirectly for the latter.

Later,
Drew
.NET MVP

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to