代理, 将方法作为另一方法的参数. 类似C里面的函数指针. using System; using System.Windows.Forms; using System.Threading; namespace Demo { public delegate void Greeting(string name); public class Demo { private static void GreetingEnglish(string name) { Console.WriteLine ("He…
这是我最常用也是最有用的重构之一.我们对方法/类/参数的命名往往不那么合适,以至于误导阅读者对于方法/类/参数功能的理解.这会造成阅读者的主观臆断,甚至引入bug.这个重构看起来简单,但却十分重要. public class Person { public String FN{ get ; set; } public Double ClcHrlyPR(){ // code to calculate hourly payrate 'return 0d;}} 如你所见,我们的类/方法/参数的名称十分…
A delegate is a type that safely encapsulates a method, similar to a function pointer in C and C++. Unlike C function pointers, delegates are object-oriented, type safe, and secure. The type of a delegate is defined by the name of the delegate. The f…
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Windows.Forms; namespace LamdaSimple { public partial cla…