ref keyword in c#.net
Ref keyword is useful for passing the reference address of the variable to other method. Before passing we must initialize that variable.out is also a keyword in c#.net which is having bit different feature. We can see out keyword here.
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace OOPSConcepts { class Program { static void Main(string[] args) { //variable should be initialized before using with ref keyword. int SeconeNumber=0; int result = 0; result = Add(ref SeconeNumber); Console.WriteLine(result); //40 Console.WriteLine(SeconeNumber); //20 Console.Read(); } public static int Add(ref int secondNumber) { // we can assign any other value to variable secondNumber = 20; return secondNumber +20; } } }
See more OOPS DOTNET Interview Questions
See more ASP.NET, C#.NET, SQL Server and more Interview Questions
Post a Comment
Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.