Click here to Skip to main content
15,900,816 members
Home / Discussions / C#
   

C#

 
GeneralRe: What Are Structs For In C#? Pin
Colin Angus Mackay19-Aug-08 11:57
Colin Angus Mackay19-Aug-08 11:57 
JokeRe: What Are Structs For In C#? Pin
PIEBALDconsult19-Aug-08 13:28
mvePIEBALDconsult19-Aug-08 13:28 
GeneralRe: What Are Structs For In C#? Pin
Colin Angus Mackay19-Aug-08 14:16
Colin Angus Mackay19-Aug-08 14:16 
GeneralRe: What Are Structs For In C#? Pin
chaiguy133719-Aug-08 15:30
chaiguy133719-Aug-08 15:30 
GeneralRe: What Are Structs For In C#? Pin
vikas amin20-Aug-08 5:44
vikas amin20-Aug-08 5:44 
GeneralRe: What Are Structs For In C#? Pin
Guffa19-Aug-08 22:34
Guffa19-Aug-08 22:34 
GeneralRe: What Are Structs For In C#? Pin
vikas amin20-Aug-08 5:49
vikas amin20-Aug-08 5:49 
AnswerRe: What Are Structs For In C#? Pin
DaveyM6919-Aug-08 12:21
professionalDaveyM6919-Aug-08 12:21 
Consider this example class and struct
public class MyClass
{
    public int Variable;
}
public struct MyStruct
{
    public int Variable;
}
They are identical apart from being a class/struct.

Now try this on these:
MyClass myClassA = new MyClass();
myClassA.Variable = 5;
MyClass myClassB = myClassA;
myClassB.Variable = 3;
Console.WriteLine(myClassA.Variable);
MyStruct myStructA = new MyStruct();
myStructA.Variable = 5;
MyStruct myStructB = myStructA;
myStructB.Variable = 3;
Console.WriteLine(myStructA.Variable);
When the value of Variable is changed in myClassB it also changes the value of Variable in myClassA. This is because when we did MyClass myClassB = myClassA; it didn't copy the value in A to B - it referenced B to the same memory location that A was pointing to. That's passing by reference.
Structs are passed by value so a copy of myClassA is made and myClassB points to the copy.

Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Expect everything to be hard and then enjoy the things that come easy. (code-frog)

GeneralRe: What Are Structs For In C#? Pin
Csharp_Raja19-Aug-08 22:59
Csharp_Raja19-Aug-08 22:59 
Questionaxmediaplayer and e.newState [modified] Pin
electriac19-Aug-08 10:17
electriac19-Aug-08 10:17 
AnswerRe: axmediaplayer and e.newState Pin
electriac19-Aug-08 11:21
electriac19-Aug-08 11:21 
QuestionTrying to use old assembly version? Pin
eggsovereasy19-Aug-08 9:25
eggsovereasy19-Aug-08 9:25 
AnswerRe: Trying to use old assembly version? Pin
leppie19-Aug-08 23:11
leppie19-Aug-08 23:11 
GeneralRe: Trying to use old assembly version? Pin
eggsovereasy20-Aug-08 4:20
eggsovereasy20-Aug-08 4:20 
Questionlock .net code Pin
sepel19-Aug-08 4:57
sepel19-Aug-08 4:57 
AnswerRe: lock .net code Pin
Manas Bhardwaj19-Aug-08 5:05
professionalManas Bhardwaj19-Aug-08 5:05 
GeneralRe: lock .net code Pin
Colin Angus Mackay19-Aug-08 5:25
Colin Angus Mackay19-Aug-08 5:25 
GeneralRe: lock .net code Pin
Paul Conrad19-Aug-08 5:35
professionalPaul Conrad19-Aug-08 5:35 
GeneralRe: lock .net code Pin
MarkB77719-Aug-08 12:44
MarkB77719-Aug-08 12:44 
AnswerRe: lock .net code Pin
hammerstein0519-Aug-08 5:34
hammerstein0519-Aug-08 5:34 
GeneralRe: lock .net code Pin
Paul Conrad19-Aug-08 5:39
professionalPaul Conrad19-Aug-08 5:39 
AnswerRe: lock .net code Pin
Paul Conrad19-Aug-08 5:37
professionalPaul Conrad19-Aug-08 5:37 
GeneralRe: lock .net code Pin
led mike19-Aug-08 6:04
led mike19-Aug-08 6:04 
JokeRe: lock .net code Pin
Bassam Saoud19-Aug-08 9:18
Bassam Saoud19-Aug-08 9:18 
AnswerRe: lock .net code Pin
chaiguy133719-Aug-08 15:42
chaiguy133719-Aug-08 15:42 

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.