Skip to main content

Posts

Showing posts with the label New Features in .NET 4.0

New feature in .NET 4.0 : Optional parameters -- Step by Step to Advanced -- Part 1

Optional Parameters: .NET introduced a new feature called Optional parameters in the version 4.0, where you can leave a particular parameter in the calling method and CLR will automatically assign the default value (That you need to provide prior) Example: Let's have a Console Application to discuss this,     class Program     {         static void Main(string[] args)         {             MyClass myclass = new MyClass();             myclass.MyMethod();             Console.ReadLine();         }     }     class MyClass     {         public void MyMethod()         {             Console.WriteLine("In MyMethod - No Parameters");         }     } Output: In MyMethod - No Parameters Adding one more MyMethod with a single int parameter         public void MyMethod(int a = 10)         {             Console.WriteLine("In MyMethod - Single Parameters");         } Then calling