Free mag vol1 | Page 193

CHAPTER 4  CORE C# PROGRAMMING CONSTRUCTS, PART II To illustrate working with optional arguments, assume you have a method named EnterLogData(), which defines a single optional parameter: static void EnterLogData(string message, string owner = "Programmer") { Console.Beep(); Console.WriteLine("Error: {0}", message); Console.WriteLine("Owner of Error: {0}", owner); } Here, the final string argument has been assigned the default value of "Programmer", via an assignment within the parameter definition. Given this, we can call EnterLogData() from within Main() in two manners: static void Main(string[] args) { Console.WriteLine("***** Fun with Methods *****"); ... EnterLogData("Oh no! Grid can't find data"); EnterLogData("Oh no! I can't find the payroll data", "CFO"); } Console.ReadLine(); Because the first invocation of EnterLogData() did not specify a second string argument, we would find that the programmer is the one responsible for losing data for the grid, while the CFO misplaced the payroll data (as specified by the second argument in t