public string Foo(object obj) {
return null;
}
public string Foo(string str) {
return null;
}
var x = Foo((dynamic) "abc");
Why is x dynamic, compiler not smart enough or I miss something important?
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.
I’m just guessing here, but…
When you add a cast to
dynamic, the entire expression becomes a dynamic expression. The result of a dynamic expression is always going to bedynamicbecause everything is resolved at run-time.Check out the MSDN page on using
dynamicfor more info:Using Type dynamic (C# Programming Guide)
And scroll to the following text: