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

<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學(xué)習(xí)心得

      時(shí)間:2021-06-12 18:14:36 心得體會(huì) 我要投稿

      關(guān)于net學(xué)習(xí)心得

        .net學(xué)習(xí)心得

      關(guān)于net學(xué)習(xí)心得

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

        下面來(lái)演示一下反射的實(shí)例

       。1)新建一個(gè)類(lèi)庫(kù)項(xiàng)目。在解決方案上單擊右鍵選擇添加“新建項(xiàng)目”,在彈出來(lái)的.框中選擇“類(lèi)庫(kù)”,在下面名字欄中輸入classlib。然后刪除class1類(lèi),新添加一個(gè)類(lèi)“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);

        }

        }

        }

        添加完之后編譯生成一下,就會(huì)在這個(gè)類(lèi)庫(kù)項(xiàng)目中的bindebug中有一個(gè)classlib.dll文件。然后添加一個(gè)控制臺(tái)應(yīng)用程序。引入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("列出程序集中的所有類(lèi)型");

        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類(lèi)中的所有的方法");

        methodinfo[] md = classperson.getmethods();

        foreach(methodinfo m in md)

        {

        console.writeline(m.name);

        }

        console.writeline("實(shí)例化classperson類(lèi),并調(diào)用sayhello方法");

        object obj = activator.createinstance(classperson);

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

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

        mysayhello.invoke(obj, null);//無(wú)參數(shù)構(gòu)造函數(shù)

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

        console.readkey();

        }

        }

        }

        運(yùn)行之后的結(jié)果是:

        列出程序集中的所有類(lèi)型

        classperson

        列出classpersonl類(lèi)中的所有的方法

        get_name

        set_name

        get_sex

        set_sex

        get_age

        set_age

        sayhello

        tostring

        equals

        gethashcode

        gettype

        實(shí)例化classperson類(lèi),并調(diào)用sayhello方法

        hello world

        hello,飛鷹

        2.using的作用

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

       。2)using別名。

        格式:using 別名=包括詳細(xì)命名空間信息的具體的類(lèi)型

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

        using aclass=namespace1.myclass;

        using bclass=namespace2.myclass;

        實(shí)例化時(shí):

        aclass my1=new aclass;

        bclass my2=new bclass;

        (3)using定義范圍

        即時(shí)釋放資源,在范圍結(jié)束時(shí)處理對(duì)象。例如:

        using(class1 cls1=new class1())

        {

        }

        在這個(gè)代碼段結(jié)束時(shí)會(huì)觸發(fā)cls1的dispose方法釋放資源。

      【net學(xué)習(xí)心得】相關(guān)文章:

      關(guān)于NET學(xué)習(xí)心得文集07-13

      net實(shí)習(xí)周記07-25

      My Net Friend作文11-07

      有關(guān)Net實(shí)驗(yàn)的報(bào)告范文10-28

      net后綴的單詞20個(gè)09-24

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

      net后綴的單詞10個(gè)09-20

      5個(gè)net后綴的單詞07-27

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