Is there a way to convert between the type of the Ref parameter and the non-ref version in C #

I look at method parameters and retrieve types. I return (for example) "System.String &" because the parameter is an out parameter. I want to know if a parameter is a string - but there seems to be no way to convert String & to its non-ref counterpart.

Can someone point me in the right direction?

Thank!

+3
source share
1 answer

Type.GetElementType

, , , null, .

:

var stringRefType = typeof(string).MakeByRefType();
var stringType = stringRefType.GetElementType();
Console.WriteLine(stringType == typeof(string)); // True
+9

Source: https://habr.com/ru/post/1756743/


All Articles