public static void Refer(ref int a,ref int b)
in this how do i find that these variables are reference variable programatically ..how do i find their type
public static void Refer(ref int a,ref int b) in this how do i find
Share
Do you mean you want to know via reflection that the method parameters are by-ref?
You use
MethodBase.GetParametersto get the parameters for the method, and thenParameterInfo.ParameterTypeto find the type of the parameter andType.IsByRefto check whether or not it’s passed by reference.Here’s a quick example:
You can’t do this in a ‘strong’ way for a variable using
a.GetType()ortypeof(a)etc.GetType()finds the type of the value ofa, which is just anint.