This doesn’t compile, but what I’m trying to do is simply casting object to ‘t’ which is passed to the function?
public void My_Func(Object input, Type t)
{
(t)object ab = TypeDescriptor.GetConverter(t).ConvertFromString(input.ToString());
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could do something like:
however, it looks like you want to use
abin a strongly-typed manner, which you can only do so by using generics: