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 :: c# async task constructor 
Csharp :: how to create a string in c# 
Csharp :: how to use var in c# 
Csharp :: c# sequential struct with fixed array size 
Csharp :: pork hub 
Csharp :: how to use date range picker in asp.net C# 
Csharp :: muovere un elemento in c# 
Csharp :: c# how to refresh input field 
Csharp :: unity color mix 
Csharp :: c# driver.findelement to look for declared variable 
Csharp :: system.componentmodel.dataannotations hide field 
Csharp :: Read csv file into wpf C# 
Csharp :: Go Statement in CSharp 
Csharp :: Bedingungen in C# – if, else und else if 
Csharp :: infinit range loop c# 
Csharp :: .net console arguments 
Csharp :: Camera follow player script unity 
Csharp :: C# decimal built-in methods 
Csharp :: How to change color of a column in RDLC report 
Csharp :: Include multiple siblings at the Level 
Csharp :: UnityEngine.Mesh:get_vertices() 
Csharp :: aps.net core mvc chek box 
Csharp :: how to know if object with a certain tag exists unity c# 
Csharp :: c# convert float to string 
Csharp :: Helper Routine GetRect¶ Calculates the area of a scaled down page: 
Csharp :: Expression And Filter 
Csharp :: visibility bound to radio button wpf 
Csharp :: how to use mongodb search index in c# 
Csharp :: how to do if statement based on date in asp net c# 
Csharp :: button next for picturebox c# 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =