Posts

Showing posts with the label C#

New features added to C# 5.0

 C#most recent version 5.0 was released on August 15, 2012 with .NET Framework 4.5 and Visual Studio 2012. There are two main features in C# 5.0 - Async Programming and Caller Information. Let's understand both these features in details as given below. Async Feature (Asynchronous Methods) C# 5.0 Async feature introduces two keywords async and await which allows you to write asynchronous code more easily and intuitively like as synchronous code. Before C# 5.0, for writing an asynchronous code, you need to define callbacks (also known as continuations) to capture what happens after an asynchronous process finishes. This makes your code and other routine task such exception handling complicated. Both the keywords are used in a combination of each other. Hence, an await operator is applied to a one or more than one expressions of an async method. An async method returns a Task or Task<TResult> that represents the ongoing work of the method. The task contains information t

Constructors & Types of Constructor in C# with Examples

Generally constructor name should be same as class name. If we want to create constructor in a class we need to create a constructor method name same as class name check below sample method for constructor class   SampleA { public  SampleA() { Console .WriteLine( "Sample A Test Method" ); } } Types of Constructors Basically constructors are 5 types those are       1.      Default Constructor       2.      Parameterized Constructor       3.      Copy Constructor       4.      Static Constructor       5.      Private Constructor Default Constructor A constructor without having any parameters called default constructor. In this constructor every instance of the class will be initialized without any parameter values like as shown below using  System; namespace  ConsoleApplication3 { class   Sample { public   string  param1, param2; public  Sample()      // Default Constructor { param1 =  "Welcome&q