Operator overloading is like sugar: a little is sweet, but a lot will make you sick. Ensure that you only use this technique for situations that...
Implement the INotifyPropertyChanged interface (located inSystem.ComponentModel). using System.ComponentModel; ... class MyDataClass :...
You can index by any type. The most common index types are int and string. Implement a Numerical Index You use the array access brackets to...
Because you often don’t know how your type will be used, making the objects sortable is highly recommended whenever possible. In the Vector3d...
You almost always want to override GetHashCode(), especially with value types, for performance reasons. Generating a hash value is generally done...
You should override Object.Equals() and also implement the IEquatable<T> interface. By default, Equals() on a reference type checks to see if...
To get a simple string representation of the vertex, override ToString() to return a string of your choosing. public override string ToString()...
By default, ToString() will display the type’s name. To show your own values, you must override the method with one of your own. To illustrate...
When designing class hierarchies, you often need to decide whether classes at the root of the hierarchy (the parent classes) should be abstract...
Mark your class as abstract. public abstract MyClass { ... } public MyDerivedClass : MyClass { ... } MyClass myClass = new MyClass();...
How to Create a Struct in C Sharp 4.0 Unlike in C++, where structs and classes are functionally identical, in C#, there are important and...
How to Implement Interfaces in C Sharp 4.0 A class can implement multiple interfaces, separated by commas: public class AudioFile : IPlayable,...
How to Create an Interface in C Sharp 4.0 Here’s a sample interface for some kind of playable object—perhaps an audio or video file, or even a...
How to Override a Base Class’s Method or Property in C Sharp 4.0 The base class’s method or property must be declared virtual and must be...
How to Call a Base Class Constructor in C Sharp 4.0Similar to calling other construct Similar to calling other constructors from the constructor...
How to Derive from a Class in C Sharp 4.0 You need to specialize a class by adding and/or overriding behavior. Use inheritance to reuse the...
How to Reuse Code in Multiple Constructors in C Sharp 4.0 Problem: You have multiple constructors, but they have a subset of functionality that...
How to Use const and readonly in C Sharp 4.0 Both const and read only are used to define data that does not change, but there are important...
How to Initialize Properties at Construction in C Sharp 4.0 Use object initialization syntax, as in the following example: class Person {...
How to Add a Constructor in C Sharp 4.0 Define a special method, called a constructor, with the same name as the class, with no return type. A...
Separate names with a comma.