2010/12/12

New "dynamic" Keyword in C# 4

Instead of doing this:

object calc = GetCalculator();
Type calcType = calc.GetType();
object res = calcType.InvokeMember("Add",
    BindingFlags.InvokeMethod, null,
    new object[] { 10, 20 });
int sum = Convert.ToInt32(res);

Do this now:

dynamic calc = GetCalculator();
int sum = calc.Add(10, 20);

Thanks to Scott Hanselman by his post.

2 comments:

  1. It’s amazing in support of me to truly have a web site that is valuable meant for my knowledge.

    ReplyDelete
  2. Changes even lessened the trouble style an incredible product to indicate search expression generate a web site that may be very relatively easy https://www.tmcnet.com/topics/articles/2019/03/12/441554-finding-right-provider-digital-seo-marketing.htm. Every person using a Search engine marketing firm is having been quite informed along with helpful. Advise them to search engine optimization help.

    ReplyDelete