Skip to content
Discussion options

You must be logged in to vote

No, currently you cannot do out ref T value. The real type of the parameter is still T; ref is a modifier showing that the parameter is passed by reference.

To do that you need to wrap your T onto another object, like a Box<T> or something that basically acts like a reference to T. Your box could be either of the two, depending on how you lay your structure:

Class

public class Box<T>
{
    public T Value { get; set; }
}

Struct - Unsafe

public ref struct Ref<T>
{
    private ref T value;

    public ref T Value
    {
        get => ref value;
    }
    
    public unsafe void SetValue(ref T value)
    {
        this.value = ref value;
    }
}

Usually, the simplest and safest option is by d…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by XNTEABDSC
Comment options

You must be logged in to vote
1 reply
@Rekkonnect
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants