Created
February 19, 2013 17:57
-
-
Save abbas-oveissi/4988241 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 (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