Generics provides the type safe code with re-usability like as algorithm. In algorithms such as sorting, searching, comparing etc. you don’t specify what data type(s) the algorithm operates on. The algorithm can be operates with any types of data. In the same way Generics operate, you can provide different data type to Generics.
In the learning phase developer are not much aware of the difference between primitive, FCL (framework class library), reference, and value types. This cause bugs and performance issues into the code. In this article, I would like to expose the different behavior of integer type.
Type Casting is the mechanism to convert one data type to another. While type casting of one data type to another, we get exception if the previous one data type is not compatible with the new data type. To avoid this exception, we have IS and AS operator in C# for safe type casting. Let's understand how to use both of them.
In ASP.Net Technology Both "Server" and "Response" are objects of ASP.Net. Server.Transfer and Response.Redirect both are used to transfer a user from one page to another. But there is some remarkable difference between both the object.
Partial class, interface and structure was introduced in C# 2.0. Now it is possible to split the definition of an class, interface and structure over more than one source files. Moreover the other parts of the class, struct, or interface should be defined in the same namespace or assembly. All the parts must have the partial keyword and same access modifier like as public, private,so on.
A partial method is a special method that exist with in a partial class or struct. One part of the partial class or struct have only partial method declaration means signature and another part of the same partial class or struct may have implementation for that partial method.
In C#, Constructors are the special types of methods of a class which get executed when it's object is created. Constructors are responsible for object initialization and memory allocation of its class. There is always at least one constructor in every class. If you don't write a constructor in class, C# compiler will automatically provide one constructor for that class.
In .net 3.5 some new generic delegates -Func<T>, Action<T> and Predicate<T> were introduced. Using generic delegates, it is possible to concise delegate type means you don’t have to define the delegate statement. These delegates are the Func<T>, Action<T> and Predicate<T> delegates and defined in the System namespace.
Delegate is a reference type that holds the reference of a class method. Any method which has the same signature as delegate can be assigned to delegate. Delegate is like function pointer in C++. There are three aspects to a delegate: Declaration, Instantiation and Invocation.
An extension method is a static method of a static class that can be invoked using the instance method syntax. Extension methods are used to add new behaviors to an existing type without altering. In extension method "this" keyword is used with the first parameter and the type of the first parameter will be the type that is extended by extension method.
The concept of lamda expression was introduced in C# 3.0. Basically, Lamda expression is a more concise syntax of anonymous method. It is just a new way to write anonymous methods. At compile time all the lamda expressions are converted into anonymous methods according to lamda expression conversion rules.
The concept of anonymous method was introduced in C# 2.0. An anonymous method is inline unnamed method in the code. It is created using the delegate keyword and doesn’t required name and return type. Hence we can say, an anonymous method has only body without name, optional parameters and return type.
var data type was introduced in C# 3.0. var is used to declare implicitly typed local variable means it tells the compiler to figure out the type of the variable at compilation time. A var variable must be initialized at the time of declaration.
C# is developed by microsoft and comes after C, C++, Java. It inherits the properties of C, C++, Java, VB. We can say C# is smart and intelligent sister of Java because it do work smartly.