1
Answer

out keyword in C#

Sachin Chauhan

Sachin Chauhan

11y
1.2k
1

 Hi All,

When i am executing the below below program, I am getting the output as 10 while i am not assigning the val1 to i. So can anybody tell me plz why it is happening?

 

class Class1

{

int i;

int Method1(out int val1)

{

val1 = 10;

return i;

}

public static void Main(String[] args)

{

int x;

Class1 cls = new Class1();

cls.Method1(

out x);

Console.WriteLine(x);

Console.ReadLine();

}

}

v
Answers (1)