您的位置:程序门 -> .net技术 -> c#



如何在函数的参数中传递类型?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何在函数的参数中传递类型?[已结贴,结贴人:zhengqing_china]
发表于:2007-09-30 11:57:54 楼主
问题如题。
例如:
    public   class   demoform   :   form
    {
          public   int   value
          {   get;   set;}
    }

    class   program
    {
        public   static   void   showform(formclass   aformclass)     //   问题1   如何定义   formclass
        {
            form   aform   =   new   aformclass();
            aform.show();
        }
        static   void   main()
        {
            showform(demoform);
        }
    }
发表于:2007-09-30 12:01:211楼 得分:0
用基类form,或者用object都可以
在函数内转换就行了
发表于:2007-09-30 12:22:342楼 得分:20
lz试试这个:
c# code
public static void showform(type formtype) { object obj = activator.createinstance(formtype); form t = obj as form; if (t != null) { t.show(); } }
发表于:2007-09-30 12:31:583楼 得分:0
水月流影   的方法可行


可是可不可以象delphi这样定义   formclass   =   class   of   tform


快速检索

最新资讯
热门点击