[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"} );

 

posted @ 2018-05-08 10:41  h.yl  阅读(116)  评论(0编辑  收藏  举报