C#语言实现类似这样的效果: 3.grams.flour

C#语言实现类似这样的效果:  3.grams.flour
参考 Martin Fowler《领域特定语言》第387页的代码,我做如下实现。
3.chi(), 三尺 转换为国际标准单位制米。

  1. namespace int_ext
  2. {
  3.     class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             System.Console.WriteLine( 3.chi() ); // output 0.999
  8.         }
  9.     }
  10.     public static class int_e
  11.     {
  12.         public static double chi(this int arg)
  13.         {
  14.             return arg * 0.333;
  15.         }
  16.     }
  17. }

Leave a Reply

Your email address will not be published. Required fields are marked *