Can't assign value to structure in array? this discussion was going on here some time ago without satisfactory conclussion at least from my point of view. here is my answer:
i have come cross a similar problem when having a struct representing id3 tag being part of node which was class instance .. later when i wanted to change value of that id3 tag; from the code eg.
Mp3Node node = treeView1.Activ eNode;
node.tag = new id3("Derric May"); //calling some struct constructor ..
this had no effect on the value of the actual node in the treeView
so my solution is to make a new procedure within Mp3Node class to alter the value of tag struct eg:
public class Mp3Node: TreeViewNode
{
...
public struct id3
{....}
public id3 tag;
public void AssignTag(id3 tg)
{
this.tag.value1 = tg,value1;
this.tag.value2 = tg.value2;
...
}
In my understanding this is because struct and class instance have different life circle and thus when pulling the struct tag outside of its class instance residency even to just assign it with a new value it has to create a copy of that value type because the class instance might get garbage collected in the next moment etc ..
Hope this will be helpfull for newbies in C# and dot net
Tomas Votruba
i have come cross a similar problem when having a struct representing id3 tag being part of node which was class instance .. later when i wanted to change value of that id3 tag; from the code eg.
Mp3Node node = treeView1.Activ eNode;
node.tag = new id3("Derric May"); //calling some struct constructor ..
this had no effect on the value of the actual node in the treeView
so my solution is to make a new procedure within Mp3Node class to alter the value of tag struct eg:
public class Mp3Node: TreeViewNode
{
...
public struct id3
{....}
public id3 tag;
public void AssignTag(id3 tg)
{
this.tag.value1 = tg,value1;
this.tag.value2 = tg.value2;
...
}
In my understanding this is because struct and class instance have different life circle and thus when pulling the struct tag outside of its class instance residency even to just assign it with a new value it has to create a copy of that value type because the class instance might get garbage collected in the next moment etc ..
Hope this will be helpfull for newbies in C# and dot net
Tomas Votruba