palermo4 posted on February 16, 2010 09:25

I am testing the new optional parameters in C#.  I am also testing the my new Windows Live Writer plug-in for code snippets.

// Testing optional parameters in C# 4.0
public static void DisplayMessage(string message = "NO SOUP FOR YOU") 
{
    Console.WriteLine("{0}: {1}", DateTime.Now, message);
}

Now this is how to execute one way or another…

static void Main(string[] args)
{
    // calling with parameter
    DisplayMessage("Favorite comedy line...");
    
    // calling with named parameter
    DisplayMessage(message: "Drum roll...");
    
    // calling without parameter
    DisplayMessage();
}

Posted in: code  Tags:
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010 J. Michael Palermo IV