|
||
|
|||||||
| New Join Forum So your new to RunUO and looking to work with people that are new, this is the place. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Forum Newbie
Join Date: Mar 2004
Posts: 97
|
I have been buring myself in books lately and am having trouble with the way this author is trying to explain the way References work within a script
For Example: Code:
//build your PC
Computer desktop = new desktop();
desktop.brand = "Dell";
//it belongs to your company also
Computer yourCompaniesDesktop = desktop
//changing one changes the other
yourCompaniesDesktop.brand = "Gateway";
Console.WriteLine("your PC is a " + desktop.brand);
Could someone help to explain References to me? Thanks in advance. |
|
|
|
|
|
#2 (permalink) |
|
Forum Expert
|
It looks like since you PC is owned by the Company, that is the "Umbrella" your PC falls under. In other words, The Hirearchy is Your company than you so to speak. So, if you change something that is higher Hirearchy, it would affect anything under it or associated under it. Make since?
|
|
|
|
|
|
#3 (permalink) | |
|
I R TEH POSTING!!1!eleven
Join Date: Jan 2004
Posts: 1,617
|
When a variable contains a value type, such as a string ("Blah") or int (42), it contains the actual sequence of bytes that make up that value (0x42 0x6c 0x61 0x68 0x00, and 0x2a 0x00 0x00 0x00 respectively), and copying the variable copies the contents byte-for-byte, creating a fresh copy of the value.
When a variable contains a reference type, it points to a sequence of bytes somewhere in memory. When the variable is copied, only the reference is copied, not the actual sequence of bytes. Both variables therefore contain a reference to the same sequence, and any change done via one variable is reflected in the other.
__________________
Get your C# documentation today! Quote:
abralka@doramail.com |
|
|
|
|
|
|
#5 (permalink) |
|
Forum Newbie
Join Date: Mar 2004
Posts: 97
|
**Thinking out loud**
So what it seems like is that members of objects can be shared in thier references as long as the objects are in the same class. So as long as i change the member "Brand" it will change the reference in both objects not just the member of the one object if they are of the same class. hope you guys can follow that bable. Is that right? |
|
|
|
|
|
#6 (permalink) |
|
Join Date: Feb 2004
Location: Canada eh
Posts: 413
|
Perhaps if you take a peek at this guys site you might be able to follow it through a bit better.
http://www.jaggersoft.com/csharp_course/index.html I found his diagrams showing the data and pointers as they're implemented between the stack and the heap to greatly clarify things for myself. --------------------------------------------------------- awdball (old school c coder learning and luvin c#)
__________________
awdball |
|
|
|
|
|
#7 (permalink) | ||
|
I R TEH POSTING!!1!eleven
Join Date: Jan 2004
Posts: 1,617
|
Quote:
__________________
Get your C# documentation today! Quote:
abralka@doramail.com |
||
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|