reflect2.cs

来自「c#的学习资料 书上的东西 很难找到的啊」· CS 代码 · 共 34 行

CS
34
字号
// Reflect2.cs -- Uses reflection to execute a class method indirectly.
//
//                Compile this program with the following command line:
//                    C:>csc Reflect2.cs
//
using System;
using System.Reflection;

namespace nsReflect
{
    class clsReflection
    {
        private double pi = 3.14159;
        public double Pi
        {
            get {return (pi);}
        }
        public string ShowPi ()
        {
            return ("Pi = " + pi);
        }
    }
    class clsMain
    {
        static public void Main ()
        {
            clsReflection refl = new clsReflection ();
            Type t = refl.GetType();
            MethodInfo GetPi = t.GetMethod ("ShowPi");
            Console.WriteLine (GetPi.Invoke (refl, null));
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?