Parameters Articles

Passing Parameters in C#

There are three primary methods of passing parameters to C# methods: Regular Parameter Passing This is passing parameters with no modifying keywords : void MyMethod(Student studentObj, int aNumber) { aNumber += 5; studentObj.Name = “Jon”; } In the above example MyMethod takes two parameters – a Student object and an Integer. Note the difference between […]

Read more

C# 4.0 – Named Parameters

C# 4.0 introduces named parameters which is primarily for code readability or for use with optional parameters.Named parameters free developers from the requirement to remember or to look up the order of parameters in the method’s signature. The parameter for each argument can be specified by providing the parameter name. For example, a function which […]

Read more

C# 4.0 – Optional Parameters

New with C# 4.0 are optional parameters which have been offered in VB for some time. Optional Parameters can be used as an alternative to overloading methods. For example private string nameMethod(string firstName, string secondName = “Obama”, int age = 49) { return firstName + ” ” + secondName; } The first parameter is a […]

Read more

Parameter passing in C#

Many people have become fairly confused about how parameters are passed in C#, particularly with regard to reference types. This page should help to clear up some of that confusion. If you have any suggestions for how it can be made clearer, please mail me. Microsoft also has a good page about this topic (which […]

Read more