Created
February 19, 2013 17:58
-
-
Save abbas-oveissi/4988253 to your computer and use it in GitHub Desktop.
sample C# code for Value vs Reference Types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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