S
Sam Sungshik Kong
Hello!
I want to know when I have to use "new" for struct creation.
//---------Case 1
struct S
{
public int I;
}
//...
S s;
s.I = 3; //OK
//---------Case 2
struct S
{
int i;
public int I
{
get {return i;}
set {i = value;}
}
}
//...
S s;
s.I = 3; //ERROR. Use of unassigned local variable 's'
//...
S s = new S();
s.I = 3; //OK
So I assumed that if a struct has a property I have to use "new".
But this was wrong.
Point p;
p.X = 3; //OK
X is a property of Point struct.
When do I have to use "new" and when do I not need to?
TIA.
Sam
I want to know when I have to use "new" for struct creation.
//---------Case 1
struct S
{
public int I;
}
//...
S s;
s.I = 3; //OK
//---------Case 2
struct S
{
int i;
public int I
{
get {return i;}
set {i = value;}
}
}
//...
S s;
s.I = 3; //ERROR. Use of unassigned local variable 's'
//...
S s = new S();
s.I = 3; //OK
So I assumed that if a struct has a property I have to use "new".
But this was wrong.
Point p;
p.X = 3; //OK
X is a property of Point struct.
When do I have to use "new" and when do I not need to?
TIA.
Sam