I want to create a simple generic function
void Assign<T>(out T result)
{
Type type = typeof(T);
if (type.Name == "String")
{
// result = "hello";
}
else if (type.Name == "Int32")
{
// result = 100;
}
else result = default(T);
}
Usage:
int value;
string text;
Assign(value); // <<< should set value to 100
Assign(text); // <<< should set text to "hello"
My question is how do you program the code to set these values ie. the missing codes in comment section.
Thanks for any help.