using System; using System.Reflection; namespace MethodInfoDemo { public class Sample { private readonly string _name; public Sample(string val) { _name = val; } public string YourName() { return _name; } } internal class Program { private static void Main(string[] args) { var s = new Sample("Nat"); MethodInfo mi = typeof (Sample).GetMethod("YourName", new Type[] {}); Console.WriteLine(mi.Invoke(s, null)); Console.ReadLine(); } } }
0 件のコメント:
コメントを投稿