CS8328 question:out ref is avaliable #7494
-
ref type is type,so we can use "out ref T value" to do thing like return ref |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
No, currently you cannot do To do that you need to wrap your Classpublic class Box<T>
{
public T Value { get; set; }
} Struct - Unsafepublic 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 doing the |
Beta Was this translation helpful? Give feedback.
-
I think my needs are reasonable. |
Beta Was this translation helpful? Give feedback.
No, currently you cannot do
out ref T value
. The real type of the parameter is stillT
;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 aBox<T>
or something that basically acts like a reference toT
. Your box could be either of the two, depending on how you lay your structure:Class
Struct - Unsafe
Usually, the simplest and safest option is by d…