C# 4.0 新增 dynamic关键字介绍

C# 4.0 新增 dynamic关键字,提供动态编程(dynamic programming),把既有的静态对象标记为动态对象,类似javascript, Python Ruby

  dynamic calc = GetCalculator();

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

  具名参数与可选参数public StreamReader OpenFile(

  string path,

  int bufferSize =1024)

  {

  ...

  }

  调用 OpenFile 时, 顺序可以完全颠倒:

OpenFile(bufferSize:4096, path:"foo.txt");

你可能感兴趣的:(dynamic)