Click here to Skip to main content
15,898,588 members
Home / Discussions / C#
   

C#

 
AnswerRe: Confused On References Pin
Matt Gerrans19-Oct-05 16:34
Matt Gerrans19-Oct-05 16:34 
GeneralRe: Confused On References Pin
budidharma19-Oct-05 17:32
budidharma19-Oct-05 17:32 
GeneralRe: Confused On References Pin
Matt Gerrans19-Oct-05 18:07
Matt Gerrans19-Oct-05 18:07 
GeneralRe: Confused On References Pin
S. Senthil Kumar19-Oct-05 23:04
S. Senthil Kumar19-Oct-05 23:04 
GeneralRe: Confused On References Pin
budidharma20-Oct-05 3:30
budidharma20-Oct-05 3:30 
GeneralRe: Confused On References Pin
S. Senthil Kumar20-Oct-05 4:30
S. Senthil Kumar20-Oct-05 4:30 
GeneralRe: Confused On References Pin
budidharma20-Oct-05 4:51
budidharma20-Oct-05 4:51 
GeneralRe: Confused On References Pin
S. Senthil Kumar20-Oct-05 5:41
S. Senthil Kumar20-Oct-05 5:41 
This[^] might help you understand structs bettter.

Essentially, structs are passed around by value, classes by reference. For example
struct A
{
   public int x;
}

class B
{
   public int x;
}

static void Main()
{
   A structInstance = new A();
   structInstance.x = 1;
   A structInstance1 = structInstance;
   structInstance1.x = 20;

   B classInstance = new B();
   classInstance.x = 1;
   B classInstance1 = classInstance;
   classInstance1.x = 20;
}


After executing the above code, structInstance.x will be 1 and structInstance1.x will be 20. However, classInstance.x and classInstance1.x will be 20. What it means is that when you say A structInstance1 = structInstance; a new instance of A is created and contents are copied from structInstance. When B classInstance1 = classInstance; executes, classInstance1 and classInstance begin referring to the same instance of B, therefore, changing x using any of the two references gets reflected in both.

Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
GeneralRe: Confused On References Pin
budidharma20-Oct-05 6:07
budidharma20-Oct-05 6:07 
GeneralRe: Confused On References Pin
Matt Gerrans20-Oct-05 5:34
Matt Gerrans20-Oct-05 5:34 
QuestionC# 1byte-1char strings Pin
Dave Shaw19-Oct-05 10:49
Dave Shaw19-Oct-05 10:49 
AnswerRe: C# 1byte-1char strings Pin
leppie19-Oct-05 11:04
leppie19-Oct-05 11:04 
AnswerRe: C# 1byte-1char strings Pin
Dave Kreskowiak19-Oct-05 14:04
mveDave Kreskowiak19-Oct-05 14:04 
GeneralRe: C# 1byte-1char strings Pin
lmoelleb19-Oct-05 20:58
lmoelleb19-Oct-05 20:58 
AnswerRe: C# 1byte-1char strings Pin
uno freeware19-Oct-05 16:45
uno freeware19-Oct-05 16:45 
AnswerRe: C# 1byte-1char strings Pin
Daniel Turini20-Oct-05 0:07
Daniel Turini20-Oct-05 0:07 
QuestionKeyboard Events Pin
ShimiG19-Oct-05 10:31
ShimiG19-Oct-05 10:31 
AnswerRe: Keyboard Events Pin
Dave Kreskowiak19-Oct-05 10:53
mveDave Kreskowiak19-Oct-05 10:53 
GeneralRe: Keyboard Events Pin
ShimiG19-Oct-05 11:08
ShimiG19-Oct-05 11:08 
GeneralRe: Keyboard Events Pin
Patric_J19-Oct-05 11:28
Patric_J19-Oct-05 11:28 
GeneralRe: Keyboard Events Pin
ShimiG19-Oct-05 11:39
ShimiG19-Oct-05 11:39 
GeneralRe: Keyboard Events Pin
Dave Kreskowiak19-Oct-05 14:01
mveDave Kreskowiak19-Oct-05 14:01 
QuestionPrototyping unmanaged DLL's Pin
Timothy Finn19-Oct-05 10:14
Timothy Finn19-Oct-05 10:14 
AnswerRe: Prototyping unmanaged DLL's Pin
Dan Neely19-Oct-05 10:29
Dan Neely19-Oct-05 10:29 
AnswerRe: Prototyping unmanaged DLL's Pin
leppie19-Oct-05 10:33
leppie19-Oct-05 10:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.