int number = 5;
Type dynamicType = number.GetType(); // dynamic type is "int"
dynamicType x = (number as dynamicType);
int number = 5; Type dynamicType = number.GetType(); // dynamic type is int dynamicType
Share
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.
How would you expect the compiler to treat the variable
xlater in the code? It wouldn’t know anything about it… so it couldn’t resolve any method calls etc.Basically what you’re after is dynamic typing which is supported in C# 4 with the “dynamic” pseudo-type: