Tag: keyword
Params in C#
The Params keyword in C# lets the developers to specify parameter for the method that can take variable no. of arguments . For example In the above sourcecode , the method Data accepts the parameter integer array . since the parameter is marked as params , you could call the function Data with the comma seperated value like below
How to Call Other Constructors within the Same Class in C# ?
There are times when you want to avoid duplicating code and want to reuse them when working on multiple constructors . If you want to call other constructors from a constructor within the same class , you need to use the this keyword . How to Call Other Constructors within the Same Class in C# ? Below is a sample code snippet that demonstrates how…
Pass by Reference using ref keyword
You can use the keyword ref in csharp to pass a value by reference instead of call by value . using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Namespace1 { class Student { public string StudentName { get; set; } /* usage of the pass by reference using the keyword ref */ public void Add(ref int i) { i = i +…
out keyword in c#
You can use the keyword out in c# to pass the arguments by reference . The out keyword works almost the same as ref keyword but one of the difference between the out and ref keyword is that out doesn’t require the variable to be initialized where as the ref keyword requires that the variable be initialized before passing it to the function. Below is…