[c#]Extesion method

做一个类似Vb.net里面with的方法

public static void Use<T>(this T item, Action<T> work)
{
    work(item);
}

定义一个类

public class User
{
    public string name;
    public string title;
}

使用该类进行赋值

User u = new User();
u.Use(p => {p.name = "ddd"; p.title = "PM"} );

猜你喜欢

转载自www.cnblogs.com/dufu/p/9006916.html
今日推荐