Skip to content

Instantly share code, notes, and snippets.

@abbas-oveissi
Created February 19, 2013 17:57
Show Gist options
  • Save abbas-oveissi/4988241 to your computer and use it in GitHub Desktop.
Save abbas-oveissi/4988241 to your computer and use it in GitHub Desktop.
sample C# code for Value vs Reference Types
Point myPoint = new Point (0, 0); // a new value-type variable
Form myForm = new Form(); // a new reference-type variable
Test (myPoint, myForm); // Test is a method defined below
void Test (Point p, Form f)
{
p.X = 100; // No effect on MyPoint since p is a copy
f.Text = "Hello, World!"; // This will change myForm’s caption since
// myForm and f point to the same object
f = null; // No effect on myForm
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment