C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 01-21-2009, 12:29 AM   #1
WDT
Tha 1 Sick RAT
 
Join Date: Dec 2003
Posts: 267
clarification

Hello

I've just decided to add C# to my repetoire so I'm going through the language at the moment to iron out the differences between in and c++. At the moment I just need to clarify the value parameter of a method with perhaps an explanation of what's actually happening at the memory level:
Code:
IntHolder first = new IntHolder();
first.i=5;
IntHolder second = first;
first.i=6;
Console.WriteLine (second.i);

Output
: 5

Now normally I would've thought that would produce a 6 since IntHolder second = first is a reference to the same object.
__________________
A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside
WDT is offline   Reply With Quote
Old 01-21-2009, 01:09 AM   #2
Confused
 
Magos's Avatar
 
Join Date: Sep 2001
Location: Sweden
Posts: 3,125
IntHolder is a struct, which means value type (no referenses). Had it been a class the output would be 6.
__________________
MagosX.com

Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Magos is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
srand() Clarification Epo C++ Programming 2 03-03-2005 11:05 PM
Need a clarification here bithub A Brief History of Cprogramming.com 30 12-27-2004 01:06 AM
exercise clarification truth table curlious C++ Programming 1 12-18-2003 07:28 PM
A little clarification? Dr Nick C++ Programming 2 06-20-2002 01:47 PM
Clarification of Function Templates biosx C++ Programming 2 02-20-2002 11:42 AM


All times are GMT -6. The time now is 10:19 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22