Virtual Methods

Virtual methods are methods of a base class that can be overridden by a method in a derived class to provide a different implementation of that method. For example, you have…
Expression-Bodied Members

Expression-Bodied Members

Expression-bodied members is a feature introduced in C# 6 that allows you to use lambda-like syntax to simplify writing of methods, properties, operator overloads, and indexers of a class. Instead of…
Lambda Expressions

Lambda Expressions

Lambda expressions simplify the syntax of anonymous methods. For example, the program below used an anonymous method that will be assigned to a delegate. using System; namespace AnonymousMethod { public delegate void…
Extension Methods

Extension Methods

Extension methods are methods that add functionality to .NET types or types that you have defined. For example, you can extend the System.String class by adding a Reverse method that reverses the string. The following program…
Null Conditional Operator

Null Conditional Operator

The Null Conditional Operator is used for easier checking of null values for every member in object property path. We use the ?operator after a member or a method call then followed by…
Anonymous Types

Anonymous Types

You can define anonymous types which is a great way to define temporary types used for data storage types. Suppose that you just want a class that can hold three values inside…
Type Inference

Type Inference

Type inference allows a variable to infer the type being assigned to it. No more should a variable be strongly typed. C# offers the varkeyword for type inference. var myInt = 10;…
Initializers

Initializers

Initializers allow you to initialize values of properties within a class. If you have several properties for example, and you don't want to define a constructor that will get all the…
Anonymous Methods

Anonymous Methods

Anonymous methods are methods that are not actually defined, therefore, only suited for one-time use. Anonymous methods are targeted for delegates. The following shows the syntax of an anonymous method. delegate…
Events

Events

Events are behaviors or happenings that occur when the program is running. Events are often used in visual programming like windows and web forms. Some examples of events are clicking a…
null Coalescing (??) Operator

null Coalescing (??) Operator

The null coalescing operator (??) could be a binary operator that determines among the 2 operands, that area unit or can manufacture a non-null worth. this is often generally used…
Nullable Types

Nullable Types

You can make Nullable Types such as int and double to allow null to be their values. Null values are only storable to reference types like string and other objects. C# allows you to transform value…
Generic Collections

Generic Collections

We can define a generic collection which is a collection of any type that you specify. For example, we can use the List<T> class fro the System.Collections.Generics namespace. The List<T> can a collection of objects of T type.…
Type Constraints

Type Constraints

Generic code must work for every type of data. You can specify type constraints for a generic method or class which only allows type specified in the list of constraints.…
Generic Classes

Generic Classes

Generic classes are classes that accept type parameters so it's encapsulated operations can be useful to any data type. Defining a generic class is as simple as defining a generic…