在线视频国产欧美另类,偷拍亚洲一区一区二区三区,日韩中文字幕在线视频,日本精品久久久久中文字幕

<small id="qpqhz"></small>
  • <legend id="qpqhz"></legend>

      <td id="qpqhz"><strong id="qpqhz"></strong></td>
      <small id="qpqhz"><menuitem id="qpqhz"></menuitem></small>
    1. net學習心得

      時間:2021-06-12 18:14:36 心得體會 我要投稿

      關于net學習心得

        .net學習心得

      關于net學習心得

        1.反射:反射是.net中的重要機制,通過反射可以在運行時獲得.net中每一個類型,包括類、結構、委托和枚舉的成員,包括方法、屬性、事件,以及構造函數(shù)等。有了反射,既可以對每一個類型了如指掌。

        下面來演示一下反射的實例

        (1)新建一個類庫項目。在解決方案上單擊右鍵選擇添加“新建項目”,在彈出來的.框中選擇“類庫”,在下面名字欄中輸入classlib。然后刪除class1類,新添加一個類“classperson”,添加如下代碼:

        namespace classlib

        {

        public class classperson

        {

        public classperson():this(null)

        {

        }

        public classperson(string strname)

        {

        name = strname;

        }

        private string name;

        private string sex;

        private int age;

        public string name

        {

        get { return name; }

        set { name = value; }

        }

        public string sex

        {

        get { return sex; }

        set { sex = value; }

        }

        public int age

        {

        get { return age; }

        set { age = value; }

        }

        public void sayhello()

        {

        if (null==name)

        console.writeline("hello world");

        else

        console.writeline("hello," + name);

        }

        }

        }

        添加完之后編譯生成一下,就會在這個類庫項目中的bindebug中有一個classlib.dll文件。然后添加一個控制臺應用程序。引入system.reflaction的命名空間。添加的代碼如下:

        using system;

        using system.collections.generic;

        using system.linq;

        using system.text;

        using system.reflection;//添加反射的命名空間

        namespace consoleapplication4

        {

        public class program

        {

        static void main(string[] args)

        {

        console.writeline("列出程序集中的所有類型");

        assembly ass = assembly.loadfrom("classlib.dll");

        type[] mytype = ass.gettypes();

        type classperson = null;

        foreach (type p in mytype)

        {

        console.writeline(p.name);

        if (p.name=="classperson")

        {

        classperson = p;

        }

        }

        console.writeline("列出classpersonl類中的所有的方法");

        methodinfo[] md = classperson.getmethods();

        foreach(methodinfo m in md)

        {

        console.writeline(m.name);

        }

        console.writeline("實例化classperson類,并調用sayhello方法");

        object obj = activator.createinstance(classperson);

        object objname=activator.createinstance(classperson,"飛鷹");

        methodinfo mysayhello = classperson.getmethod("sayhello");

        mysayhello.invoke(obj, null);//無參數(shù)構造函數(shù)

        mysayhello.invoke(objname, null);//有參構造函數(shù)

        console.readkey();

        }

        }

        }

        運行之后的結果是:

        列出程序集中的所有類型

        classperson

        列出classpersonl類中的所有的方法

        get_name

        set_name

        get_sex

        set_sex

        get_age

        set_age

        sayhello

        tostring

        equals

        gethashcode

        gettype

        實例化classperson類,并調用sayhello方法

        hello world

        hello,飛鷹

        2.using的作用

       。1)引入命名空間,如:using system。

       。2)using別名。

        格式:using 別名=包括詳細命名空間信息的具體的類型

        例如:在兩個命名空間(namespace1,namespace2)里各有一個myclass類,這時可以這樣引入命名空間,

        using aclass=namespace1.myclass;

        using bclass=namespace2.myclass;

        實例化時:

        aclass my1=new aclass;

        bclass my2=new bclass;

        (3)using定義范圍

        即時釋放資源,在范圍結束時處理對象。例如:

        using(class1 cls1=new class1())

        {

        }

        在這個代碼段結束時會觸發(fā)cls1的dispose方法釋放資源。

      【net學習心得】相關文章:

      關于NET學習心得文集07-13

      net實習周記07-25

      My Net Friend作文11-07

      有關Net實驗的報告范文10-28

      net后綴的單詞20個09-24

      net后綴的單詞有哪些09-03

      net后綴的單詞10個09-20

      5個net后綴的單詞07-27

      我的網(wǎng)友 My Net Friend07-24