Author

Anonymous Types

Anonymous types enable you to create objects without writing a class definition for the data type. Instead, the compiler generates a class for you. The class has no usable name and contains the properties you specify in declaring the object. To create an instance of an anonymous type: // sampleObject is an instance of a... » read more

Static Classes and Members

A static member of the class is a property, procedure, or field that is shared by all instances of a class. To define a static member: static class SampleClass { public static string SampleString = "Sample String"; } Console.WriteLine(SampleClass.SampleString); Static classes in C# have static members only and cannot be instantiated. Static members also cannot... » read more

Instantiating Classes

To create an object, you need to instantiate a class, or create a class instance. SampleClass sampleObject = new SampleClass(); // Set a property value. SampleClass sampleObject = new SampleClass { FirstProperty = "A", SecondProperty = "B" };

Nested Classes

A class defined within another class is called nested. By default, the nested class is private. class Container { class Nested { // Add code here. } } To create an instance of the nested class, use the name of the container class followed by the dot and then followed by the name of the... » read more

C# Constructors

Constructors Constructors are class methods that are executed automatically when an object of a given type is created. Constructors usually initialize the data members of the new object. A constructor can run only once when a class is created. Furthermore, the code in the constructor always runs before any other code in a class. However,... » read more

Classes vs Structs

Classes Only: Can support inheritance Are reference (pointer) types The reference can be null Have memory overhead per new instance class SampleClass { } Structs Only: Cannot support inheritance Are value types Are passed by value (like integers) Cannot have a null reference (unless Nullable is used) Do not have a memory overhead per new... » read more

C# Method Overloading

In c#, Method Overloading means defining a multiple methods with same name but with different parameters. By using Method Overloading, we can perform a different tasks with same method name by passing different parameters. Suppose, if we want to overload a method in c#, then we need to define another method with same name but with different signatures. In c#,... » read more

C# Inheritance

Basic Inheritance public class Animal{ public void Greet() { Console.WriteLine("Hello, I'm some sort of animal!"); }} public class Dog : Animal{ } Animal animal = new Animal(); animal.Greet(); Dog dog = new Dog(); dog.Greet();

Access Modifiers and Access Levels

The following access modifiers are available: C# Modifier Definition public The type or member can be accessed by any other code in the same assembly or another assembly that references it. private The type or member can only be accessed by code in the same class. protected The type or member can only be accessed... » read more

Windows Presentation Foundation (WPF)

Windows Presentation Foundation (WPF) is a graphical subsystem by Microsoft for rendering user interfaces in Windows-based applications. WPF, previously known as “Avalon”, was initially released as part of .NET Framework 3.0 in 2006. WPF uses DirectX and attempts to provide a consistent programming model for building applications. It separates the user interface from business logic, and resembles similar XML-oriented object models, such as those implemented... » read more