NodeRank is a struct, so it's a value type.
ArrayList holds objects, which are reference types.
To store a value type in a object, it must be boxed.
Writing "tempNodeRank = (NodeRank)nodeRanks[i];" unboxes the struct.
"((NodeRank)nodeRanks[i]).rank" is attempting to refernce the still
boxed object.
Change NodeRank to a class, and that line will work.
--
Truth,
James Curran
[erstwhile VC++ MVP]
Home:
www.noveltheory.com Work:
www.njtheater.com
Blog:
www.honestillusion.com Day Job:
www.partsearch.com
"craig" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I am using an ArrayList named "nodeRanks" of the following structs:
>
> private struct NodeRank
> {
> public TreeNode Node;
> public Int32 Rank;
> }
>
> I sort the nodeRanks ArrayList based upon the rank values, and then I
would
> like to replace the rank values with the ArrayList index values. However,
> when I try the following approach, I get a runtime error:
>
> for(int i=0;i<=nodeRank.Count-1;i++)
> {
> ((NodeRank)nodeRanks[i]).rank = i;
> }
>
> The error that I get is: (3696): The left-hand side of an assignment must
> be a variable, property or indexer
>
> I am not sure why I am getting this error because the left side of my
> assignment is a public field (variable) of the struct. If I re-write the
> code as follows, it works. But I would still like to know why the more
> consise syntax fails.
>
> NodeRank tempNodeRank;
> for(int i=0;i<=nodeRank.Count-1;i++)
> {
> tempNodeRank = (NodeRank)nodeRanks[i];
> tempNodeRank.rank = i;
> nodeRanks[i] = tempNodeRank;
> }
>
> Thanks!!
>
>
>
>
>