A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/../keywords/ref below:

The multiple uses of the `ref` keyword - C# reference

The ref keyword

In this article

You use the ref keyword in the following contexts:

public void M(ref int refParameter)
{
    refParameter += 42;
}
public ref int RefMax(ref int left, ref int right)
{
    if (left > right)
    {
        return ref left;
    }
    else
    {
        return ref right;
    }
}
public void M2(int variable)
{
    ref int aliasOfvariable = ref variable;
}
public ref int RefMaxConditions(ref int left, ref int right)
{
    ref int returnValue = ref left > right ? ref left : ref right;
    return ref returnValue;
}
public ref struct CustomRef
{
    public ReadOnlySpan<int> Inputs;
    public ReadOnlySpan<int> Outputs;
}
public ref struct RefFieldExample
{
    private ref int number;
}
class RefStructGeneric<T, S>
    where T : allows ref struct
    where S : T
{
    // etc
}

Collaborate with us on GitHub

The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.

Additional resources

In this article

Was this page helpful?


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4