473,320 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can't assign value to structure in a class instance?

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.ActiveNode;
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
Feb 17 '12 #1
0 1293

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ñ©ÔÆÓ¥ | last post by:
Hi,all I have a trouble about struct variable,the detail is : I define a new struct which name ServiceProperty,then I declare a variable like this: ServiceProperty instService = null; ...
26
by: Brett | last post by:
I have created a structure with five fields. I then create an array of this type of structure and place the structure into an array element. Say index one. I want to assign a value to field3 of...
0
by: JJ_377 | last post by:
The following doesn't assign value to the dropdownlist - WHY? ___________________________________________________________________ In a user control (ascx named USACustomer) : Public Property...
2
by: Terry Heath | last post by:
Hi - I've tried different ways to write to the variable me, but with no luck. I've tried passing it to other methods as a byref parameter, and even though it looks like it's written to the...
5
by: Joseph Geretz | last post by:
Of course, I can store a C# class instance to the Server Cache (this.Context.Cache). I've tried it. My question is, will this destroy the scalability of my application? My background is VB6....
7
vikas251074
by: vikas251074 | last post by:
Can I assign value to cookies immediately after selecting a value from list? <select name="vlan_name" style="width:150px "> <%set rs = conn.execute("select vlan_name from vlan_master order by...
2
by: rahullko05 | last post by:
i am stuck in the problem, where after user logs in successfuly, i take him to the login thanks page. now on that page i need to retain the login name. I am not sure how to this. i have written a...
17
by: zombiezoom | last post by:
I need help with error 2448: You can't assign value to this object. What I am trying to do is allow user to select event id and race id from combo option. Once the user selects those, then the id...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.