Tag Archives: arguments

Validate optional parameters in C#

The example Use named and optional parameters in C# explains how to use named and optional parameters to let the calling code omit any combination of parameters. In many applications, you may not want to allow the user to omit … Continue reading

Posted in methods, syntax, variables | Tagged , , , , , , , , , , , , , | 1 Comment

Use named and optional parameters in C#

Optional parameters is one of the few additions in recent versions of Visual Studio that are really useful. I usually try to post examples in an older version of C# because it’s easier for someone to move an older example … Continue reading

Posted in methods, syntax, variables | Tagged , , , , , , , , , , , , , | 1 Comment

Use the params keyword in C#

If you use the params keyword before an array parameter used as the last parameter in a method, then the calling code can pass any number of values for that parameter. The following code defines a ShowValues method that can … Continue reading

Posted in methods | Tagged , , , , , , , , , , , | 4 Comments

Get command line arguments in C#

One method to do this is to override the program’s Main method and give it a parameter that is a string array as in the following code. static void Main(string[] args) { foreach (string arg in args) { lstArguments.Items.Add(arg); } … Continue reading

Posted in system | Tagged , , , , , , , , , | 1 Comment