I hope someone can help me out!! I'm fairly new to C#.
I've established a dictionary:
Dictionary<string, Point> addPositionDict = new Dictionary<string, Point>();
I initialized the dictionary:
Point addPoint = new Point();
addPoint.X = 0;
addPoint.Y = 0;
and added my points with their given names:
addPositionDict.Add(name_Out, addPoint);
Now knowing their names, I want to update their positions and I tried like so:
addPositionDict[nameOut].X = x_matrix;
However there is an error which I can't understand:
"Cannot modify the return value of 'System.Collections.Generic.Dictionary
What am I doing wrong? what exactly is not a variable? Again, Take it easy on the language "jargon" -- I'm fairly new to C#.
VulpesPosted Mar 15, 2012, 3:32 PM
Consequently, addPositionDict[name_Out].X is a value, rather than a variable, and you can't assign anything to a value.
The workaround is to do it like this:
Notice that here addPositionDict[name_Out].Y is simply being used as a value - we're not trying to assign anything to it.
If Point had been a class (i.e. a reference type) rather than a struct, then your original code would have worked because addPositionDict[name_Out].X would then have been regarded as a variable.
Marty HabichtPosted Mar 15, 2012, 3:49 PM