Out keyword c#.net
It is bit different from normal variable passing through method and ref value passing through method. Using out keyword we can use variable with out initializing. Please see below example. i have not initialize the SeconeNumber, still we can use that.using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace OOPSConcepts { class Program { static void Main(string[] args) { //variable is not initialized before calling the method. int SeconeNumber; int result = 0; result = Add(out SeconeNumber); Console.WriteLine(result); //output 40 Console.WriteLine(SeconeNumber); //output 20 Console.Read(); } public static int Add(out int secondNumber) { //Here we are initializing the variable. secondNumber = 20; return secondNumber +20; } } } output : 40 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.