G
Guest
I don't understand why I cannot use a property to modify data within a
struct. Can someone tell me why I get the error "Cannot modify the return
value of "myData.TheData" because it is not a variable.
Here is what breaks.
struct Data
{
public Data(){}
private int someData;
public int TheData
{
get { return someData; }
set { someData = value; }
}
}
class Sample
{
Data myData = new Data();
void AMethod()
{
myData.TheData = 7;
}
}
If I don't use the property "TheData" and instead make "int someData" public
I can reference myData.someData = 7 and it will work just fine. Why can't a
property be used?
struct. Can someone tell me why I get the error "Cannot modify the return
value of "myData.TheData" because it is not a variable.
Here is what breaks.
struct Data
{
public Data(){}
private int someData;
public int TheData
{
get { return someData; }
set { someData = value; }
}
}
class Sample
{
Data myData = new Data();
void AMethod()
{
myData.TheData = 7;
}
}
If I don't use the property "TheData" and instead make "int someData" public
I can reference myData.someData = 7 and it will work just fine. Why can't a
property be used?