Skip to main content

Posts

Showing posts with the label ref and out keyword in c#

Out keyword in C#

If you want to return multiple outputs from a function you will use the OUT keyword. In Out  key, When we passed variables as out arguments that time we initialized the variables within the methods. It is also known as the  output parameter . Ref keyword is a  one-way  communication while the out  keyword   is  two-way   communication. Initialized must be inside the methods.  Before calling the methods may be initialized or not initialized the values of the variables. A simple code sample is given below public class OutClass {     static void Method(int a, int b,  out int  add)     {         add = a+b;     }     static void Main()     {         int add=0;         Method(10, 10,  out add);     } } Some im...