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.

5 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
  3. If somebody wants expert take on the main topic of blogging next I advise him/her to go to this site, continue the fussy job.
    click site

    ReplyDelete
  4. This written piece gives fastidious understanding yet.It’s amazing in support of me to truly have a web site that is valuable meant for my knowledge
    UX consultant

    ReplyDelete
  5. It’s amazing to visit again n again coming to your blogs the superb effort is here.
    Lead conversion system squared

    ReplyDelete