// --------------------------------------------------------------------------------------------- // Example of reference types. // --------------------------------------------------------------------------------------------- MyNumber a, b; a = new MyNumber(5); // Store 5 in a b = a; // Copy the reference to 'MyNumber' a into b a.X = 10; // Modify a, but since b is pointing to the same object, b will change too Console.WriteLine(a.X); // Will print 10 Console.WriteLine(b.X); // Will print 10
class MyNumber { private int _x; public int X { get { return this._x; } set { this._x = value; } } public MyNumber(int x) { this._x = x; } }
string[] words = new string[] { "Word1", "Word2", "Word3" }; Console.WriteLine(String.Join(" | ", words)); // Word1 | Word2 | Word3 Console.WriteLine(String.Concat(words)); // Word1Word2Word3 StringBuilder longString = new StringBuilder(); longString.Append("Hello World"); Console.WriteLine(longString.ToString());