How do I declare inout arguments in C#?

The equivalent of inout in C# is ref. , as shown in the following

example: public void MyMethod (ref String str1, out String str2)

{

...

}

When calling the method, it would be called like this: String s1;

String s2;

s1 = "Hello";

MyMethod(ref s1, out s2);

Console.WriteLine(s1);

Console.WriteLine(s2);

Notice that you need to specify ref when declaring the function and calling it.

Showing Answers 1 - 1 of 1 Answers

Ans:

Answer:

The equivalent of inout in C# is ref. , as shown in the following

example: public void MyMethod (ref String str1, out String str2)

{

...

}

When calling the method, it would be called like this: String s1;

String s2;

s1 = "Hello";

MyMethod(ref s1, out s2);

Console.WriteLine(s1);

Console.WriteLine(s2);

Notice that you need to specify ref when declaring the function and calling it.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions