« Home | Boring Tuesday » | Monday Blues, Monday Woes » | Resignation » | I've Made A Decision! » | Hmmm... » | OMG! (good version!) » | Interviews interviews.... » | Saturday Night Home Alone » | File Lister Application » | Data Bindings in .NET »

Rainy weather, structs & classes

As usual, woke up this morning to a big downpour...so snoozed for 1/2 hour and still there's downpour....snoozed another 10 minutes still downpour...in the end i gave up...woke up my sister...and we both came to work wearing slippers...with shoes in bags.

Just realised the difference between structs and classes in .NET.

Classes are referred type whereas structs are not. Structs are just valued referenced.

Not sure if i'm making sense here, here's an example from Microsoft.



using System;

class TheClass
{
public int x;
}

struct TheStruct
{
public int x;
}

class TestClass
{
public static void structtaker(TheStruct s)
{
s.x = 5;
}
public static void classtaker(TheClass c)
{
c.x = 5;
}
public static void Main()
{
TheStruct a = new TheStruct();
TheClass b = new TheClass();
a.x = 1;
b.x = 1;
structtaker(a);
classtaker(b);
Console.WriteLine("a.x = {0}", a.x);
Console.WriteLine("b.x = {0}", b.x);
Console.ReadLine();
}
}



output:

a.x = 1
b.x = 5