N
neelsmail
Hi,
I have just started learning C# ; I was working in C++ till now (and
would like to if allowed, but learning new things dont hurt). I am
used to specifiying "const" to get the assurance that unless someone
specifically cast-away the constness, object wont change. So, as part
of my first ever program I wrote a following class -
public class FirstOne {
public int intTry;
public FirstOne() {
intTry = 0;
}
//public FirstOne(readonly FirstOne o)
//public FirstOne(const FirstOne o)
public FirstOne(FirstOne o) {
intTry = o.intTry;
o.intTry = -100; // This would be possible if I can't make
the parameter const..
}
}
Since class in C# is reference type (still getting hang of the
concept) object 'o' is already a reference, I am just trying to make
it const so that it doesn't change. But the syntax (commented lines)
does not work. Is it even possible to have const ref or it's just a
glitch in my C# syntax understanding?
Thanks in advance,
Neel.
I have just started learning C# ; I was working in C++ till now (and
would like to if allowed, but learning new things dont hurt). I am
used to specifiying "const" to get the assurance that unless someone
specifically cast-away the constness, object wont change. So, as part
of my first ever program I wrote a following class -
public class FirstOne {
public int intTry;
public FirstOne() {
intTry = 0;
}
//public FirstOne(readonly FirstOne o)
//public FirstOne(const FirstOne o)
public FirstOne(FirstOne o) {
intTry = o.intTry;
o.intTry = -100; // This would be possible if I can't make
the parameter const..
}
}
Since class in C# is reference type (still getting hang of the
concept) object 'o' is already a reference, I am just trying to make
it const so that it doesn't change. But the syntax (commented lines)
does not work. Is it even possible to have const ref or it's just a
glitch in my C# syntax understanding?
Thanks in advance,
Neel.