Skip to content

Instantly share code, notes, and snippets.

@abbas-oveissi
Created February 19, 2013 17:58
Show Gist options
  • Save abbas-oveissi/4988253 to your computer and use it in GitHub Desktop.
Save abbas-oveissi/4988253 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 (ref myPoint, ref myForm); // pass myPoint and myForm by reference
void Test (ref Point p, ref Form f)
{
p.X = 100; // This will change myPoint’s position
f.Text = “Hello, World!”; // This will change MyForm’s caption
f = null; // This will nuke the myForm variable!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment