Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# out parameter

/*
C# provides out keyword to pass arguments as out-type. 
It is like reference-type, except that it does not require variable
to initialize before passing. We must use out keyword to pass argument 
as out-type. It is useful when we want a function to return multiple values.
*/

using System;  
namespace OutParameter  
{  
    class Program  
    {  
        // User defined function  
        public void Show(out int val) // Out parameter  
        {  
            int square = 5;  
            val = square;  
            val *= val; // Manipulating value  
        }  
        // Main function, execution entry point of the program  
        static void Main(string[] args)  
        {  
            int val = 50;  
            Program program = new Program(); // Creating Object  
            Console.WriteLine("Value before passing out variable " + val);  
            program.Show(out val); // Passing out argument  
            Console.WriteLine("Value after recieving the out variable " + val);  
        }  
    }  
}  
/*
output:
Value before passing out variable 50
Value after receiving the out variable 25
*/
Comment

c# out argument

// Defining Variable inline
myMethod(out Task output);
output.Start();


// Set existing variable
Task output;
myMethod(out output);
output.Start();
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity apply bloom of a different color 
Csharp :: #dictionery in c 
Csharp :: c# invokerequired wpf 
Csharp :: extension method in c# 
Csharp :: c# int to string date conversion 
Csharp :: only specific columns in Linq 
Csharp :: wpf binding object get value 
Csharp :: sustituir un caracter de un string c# 
Csharp :: guicontrol text ahk 
Csharp :: c# dictionary check if value exists 
Csharp :: toLocalIsoString() vs toIsoString() 
Csharp :: unity2d switch camera 
Csharp :: how to find the biggest number in c# 
Csharp :: visual studio console.writeline not showing in output window 
Csharp :: unity vector3 initialization 
Csharp :: indexing an array 
Csharp :: use c#9 
Csharp :: check if list contains any empty element in c# 
Csharp :: unity3d gameobject follow path 
Csharp :: check if multiple variables are null c# 
Csharp :: c# int division to double 
Csharp :: how to show a first item in a combobox in c# winforms 
Csharp :: C# Convert xml to datatable 
Csharp :: dbset syntax 
Csharp :: c# nunit test case 
Csharp :: c# collection of generic classes 
Csharp :: Implementing video array in unity 
Csharp :: cefsharp print 
Csharp :: asp.net store list in web.config 
Csharp :: <link rel="stylesheet" href="styles/kendo.common.min.css" / 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =