Language Binding - CSharp Custom Type

CSharp examples for Custom Type:dynamic type

Introduction

Language binding occurs when a dynamic object does not implement IDynamicMetaObjectProvider.

static dynamic Mean (dynamic x, dynamic y) => (x + y) / 2;

static void Main()
{
  int x = 3, y = 4;
  Console.WriteLine (Mean (x, y));
}

Catch RuntimeBinderException

If a member fails to bind, a RuntimeBinderException is thrown. You can think of this like a compile-time error at runtime:

dynamic d = 5;
d.Hello();                  // throws RuntimeBinderException

The exception is thrown because the int type has no Hello method.


Related Tutorials