"David++" <Da***@discussions.microsoft.coma écrit dans le message de news:
54**********************************@microsoft.com...
| In C++ I was able to initialize variables in the constructor like so -
|
| private int a, b, c;
|
| public myClass() : a(0), b(0), c(0)
| {
|
| }
|
| Is this possible in C#? Tried it and it didnt seem to work.
Nope, but you can initialise fields in the declaration. Also remember that
all fields are initialised to their "0" value by the constructor anyway, so
ints will always be 0, strings will always be null, etc.
But if you need explicit initialisation to the non-default value, then you
can do this :
public class MyClass
{
private int a = 1;
private int b = 2;
private int c = 3;
public MyClass()
{
//
}
}
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer