C# FAQ: How can I declare inout arguments in CSharp?

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
CSharp-Online.NET:FAQs
edit

How can I declare inout arguments in C#?

To create the equivalent of C-style inout arguments in C#, use the ref keyword. The ref keyword is used in the following method declaration:

public void aMethod (ref String string1, out String string2) 
{
   ...
}

Such a method is called like this:

String string1, string2;
string1 = "Ref_argument";
aMethod (ref string1, out string2);

The ref keyword must be used both when declaring the method and when invoking it.

See also



Personal tools