I have a method which is something like below and i want to set the value of it with input string.
How would i go about it? Any advice will be greatly appreciated
private static void QueueCheckNAdd<T>(ref T param, string input)
{
param.DoSomethingLikeSetValue(input);
}
for your reference, the generic type is something like int or double
param = (T)(object)Convert.ChangeType(input, typeof(T));
The casts are necessary to convince the compiler that the result is really of type T
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With