M
^MisterJingo^
I'm new to C# (literally 2 days) and need a bit of help understanding
an error.
struct Blah
{
int x;
int y;
public int X
{
get
{
return x;
}
set
{
this.x = value;
}
}
public int Y
{
get
{
return y;
}
set
{
y = value;
}
}
}
class MainApp
{
public static void Main()
{
Blah test;
test.Y = 1;
}
}
With the above code I get the following error:
"Use of unassigned local variable 'test'"
But I remove the data member properties in 'struct Blah' I can happily
assign to test.y.
If I use properties (get, set)do I need to initialise the struct
members first?
an error.
struct Blah
{
int x;
int y;
public int X
{
get
{
return x;
}
set
{
this.x = value;
}
}
public int Y
{
get
{
return y;
}
set
{
y = value;
}
}
}
class MainApp
{
public static void Main()
{
Blah test;
test.Y = 1;
}
}
With the above code I get the following error:
"Use of unassigned local variable 'test'"
But I remove the data member properties in 'struct Blah' I can happily
assign to test.y.
If I use properties (get, set)do I need to initialise the struct
members first?