Constant Reference
-
Is there no way to pass an object by constant reference as you can in C++. It doesn't seem to be possible in c#. There must be some way of passing an object into a function and guaranteeing that the function does no change the object. This is a pretty basic and essential feature for writing robust code.
-
Is there no way to pass an object by constant reference as you can in C++. It doesn't seem to be possible in c#. There must be some way of passing an object into a function and guaranteeing that the function does no change the object. This is a pretty basic and essential feature for writing robust code.
here's an example of 3 different constants in C# VB:
Public Const int PBM_SETBKCOLOR = 0x2001;
Public Const int PBM_SETBARCOLOR = 0x409;
Public Const int WM_CLOSE = 0x10;
hope that helps.
My Signature
Private void ExpectingTwins(string twins)
{
switch(twins)
{
Case ("twins on the way"):
MessageBox.Show("for mr and mrs dynamic","twins on the way");
break;
}
}
-
here's an example of 3 different constants in C# VB:
Public Const int PBM_SETBKCOLOR = 0x2001;
Public Const int PBM_SETBARCOLOR = 0x409;
Public Const int WM_CLOSE = 0x10;
hope that helps.
My Signature
Private void ExpectingTwins(string twins)
{
switch(twins)
{
Case ("twins on the way"):
MessageBox.Show("for mr and mrs dynamic","twins on the way");
break;
}
}
I think SteveUK is talking about something like this in c++: void foo( const string& text ); According to Programming C# by Jesse Liberty you can pass by reference but I was not able to find anything about passing by const reference: void foo( ref string text ) { ... } The only ways I was able to find on passing parameters are: by-val, by-ref, and with the "out" modifier (which appears to be similar to by-ref.) Hope this helps. jv
-
Is there no way to pass an object by constant reference as you can in C++. It doesn't seem to be possible in c#. There must be some way of passing an object into a function and guaranteeing that the function does no change the object. This is a pretty basic and essential feature for writing robust code.
SteveUK wrote: There must be some way of passing an object into a function and guaranteeing that the function does no change the object. This is a pretty basic and essential feature for writing robust code. This is pretty much built into .NET. The following shows you:
Foo(object o)
{
o = null;
}Main()
{
Object o = new Object();
Foo(o);
WriteLine(o); //o still exists
} -
Is there no way to pass an object by constant reference as you can in C++. It doesn't seem to be possible in c#. There must be some way of passing an object into a function and guaranteeing that the function does no change the object. This is a pretty basic and essential feature for writing robust code.
non-editable parameters is not supported by the CLS nor c#. In order to simulate this, you can make a clone of the object you are passing in.