日期:2014-05-17 浏览次数:20420 次
public class Class { private string Main() { string abc = ""; Test(abc); } private void Test(string str) { //我在这个方法里怎么能得到传过来的变量名称?即"abc" } }
static void Main(string[] args) { string abc = "123"; Test(p=>abc); } private static void Test(Expression<Func<string,string>> exp) { var body = exp.Body as MemberExpression; Console.WriteLine("参数名:" + body.Member.Name); }