欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#學(xué)習(xí)基礎(chǔ)概念二十五問第1/4頁(yè)

 更新時(shí)間:2007年04月09日 00:00:00   作者:  
注:本文部份資料來自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)與我聯(lián)系,我會(huì)在第一時(shí)間聲明引用或?qū)⑵鋭h除!
    當(dāng)初學(xué) C# 時(shí)是找個(gè)人大概問了一下數(shù)據(jù)類型和分支語(yǔ)句就開始做項(xiàng)目了。這兩天又全面的看了一下相關(guān)的基礎(chǔ)知識(shí)(學(xué)而時(shí)習(xí)之嘛),總結(jié)了25個(gè)問題:
1.靜態(tài)成員和非靜態(tài)成員的區(qū)別?
2.const 和 static readonly 區(qū)別?
3.extern 是什么意思?
4.abstract 是什么意思?
5.internal 修飾符起什么作用?
6.sealed 修飾符是干什么的?
7.override 和 overload 的區(qū)別?
8.什么是索引指示器?
9.new 修飾符是起什么作用?
10.this 關(guān)鍵字的含義?
11.可以使用抽象函數(shù)重寫基類中的虛函數(shù)嗎?
12.密封類可以有虛函數(shù)嗎?
13.什么是屬性訪問器?
14.abstract 可以和 virtual 一起使用嗎?可以和 override 一起使用嗎?
15.接口可以包含哪些成員?
16.類和結(jié)構(gòu)的區(qū)別?
17.接口的多繼承會(huì)帶來哪些問題?
18.抽象類和接口的區(qū)別?
19.別名指示符是什么?
20.如何手工釋放資源?
21.P/Invoke是什么?
22.StringBuilder 和 String 的區(qū)別?
23.explicit 和 implicit 的含義?
24.params 有什么用?
25.什么是反射? 
以下是我做的一份參考答案(C# 語(yǔ)言范疇之內(nèi)),如果有不準(zhǔn)確、不全面的,歡迎各位朋友指正!
1.靜態(tài)成員和非靜態(tài)成員的區(qū)別?
答:
靜態(tài)變量使用 static 修飾符進(jìn)行聲明,在類被實(shí)例化時(shí)創(chuàng)建,通過類進(jìn)行訪問
不帶有 static 修飾符聲明的變量稱做非靜態(tài)變量,在對(duì)象被實(shí)例化時(shí)創(chuàng)建,通過對(duì)象進(jìn)行訪問
一個(gè)類的所有實(shí)例的同一靜態(tài)變量都是同一個(gè)值,同一個(gè)類的不同實(shí)例的同一非靜態(tài)變量可以是不同的值
靜態(tài)函數(shù)的實(shí)現(xiàn)里不能使用非靜態(tài)成員,如非靜態(tài)變量、非靜態(tài)函數(shù)等
復(fù)制代碼 代碼如下:

示例:
using System;
using System.Collections.Generic;
using System.Text;
namespace Example01
{
    class Program
    {
        class Class1
        {
            public static String staticStr = "Class";
            public String notstaticStr = "Obj";
        }
        static void Main(string[] args)
        {
            //靜態(tài)變量通過類進(jìn)行訪問,該類所有實(shí)例的同一靜態(tài)變量都是同一個(gè)值
            Console.WriteLine("Class1's staticStr: {0}", Class1.staticStr);
            Class1 tmpObj1 = new Class1();
            tmpObj1.notstaticStr = "tmpObj1";
            Class1 tmpObj2 = new Class1();
            tmpObj2.notstaticStr = "tmpObj2";
            //非靜態(tài)變量通過對(duì)象進(jìn)行訪問,不同對(duì)象的同一非靜態(tài)變量可以有不同的值
            Console.WriteLine("tmpObj1's notstaticStr: {0}", tmpObj1.notstaticStr);
            Console.WriteLine("tmpObj2's notstaticStr: {0}", tmpObj2.notstaticStr);
            Console.ReadLine();
        }
    }
}

結(jié)果:
Class1's staticStr: Class
tmpObj1's notstaticStr: tmpObj1
tmpObj2's notstaticStr: tmpObj2
2.const 和 static readonly 區(qū)別?
答:
const
用 const 修飾符聲明的成員叫常量,是在編譯期初始化并嵌入到客戶端程序
static readonly
用 static readonly 修飾符聲明的成員依然是變量,只不過具有和常量類似的使用方法:通過類進(jìn)行訪問、初始化后不可以修改。但與常量不同的是這種變量是在運(yùn)行期初始化
示例:
測(cè)試類:
using System;
using System.Collections.Generic;
using System.Text;
namespace Example02Lib
{
    public class Class1
    {
        public const String strConst = "Const";
        public static readonly String strStaticReadonly = "StaticReadonly";
        //public const String strConst = "Const Changed";
        //public static readonly String strStaticReadonly = "StaticReadonly Changed";
    }
}
客戶端代碼:
using System;
using System.Collections.Generic;
using System.Text;
using Example02Lib;
namespace Example02
{
    class Program
    {
        static void Main(string[] args)
        {
            //修改Example02中Class1的strConst初始值后,只編譯Example02Lib項(xiàng)目
            //然后到資源管理器里把新編譯的Example02Lib.dll拷貝Example02.exe所在的目錄,執(zhí)行Example02.exe
            //切不可在IDE里直接調(diào)試運(yùn)行因?yàn)檫@會(huì)重新編譯整個(gè)解決方案??!
            //可以看到strConst的輸出沒有改變,而strStaticReadonly的輸出已經(jīng)改變
            //表明Const變量是在編譯期初始化并嵌入到客戶端程序,而StaticReadonly是在運(yùn)行時(shí)初始化的
            Console.WriteLine("strConst : {0}", Class1.strConst);
            Console.WriteLine("strStaticReadonly : {0}", Class1.strStaticReadonly);
            Console.ReadLine();
        }
    }
}
結(jié)果:
strConst : Const
strStaticReadonly : StaticReadonly 
修改后的示例:
測(cè)試類:
using System;
using System.Collections.Generic;
using System.Text;
namespace Example02Lib
{
    public class Class1
    {
        //public const String strConst = "Const";
        //public static readonly String strStaticReadonly = "StaticReadonly";
        public const String strConst = "Const Changed";
        public static readonly String strStaticReadonly = "StaticReadonly Changed";
    }
}
結(jié)果
strConst : Const
strStaticReadonly : StaticReadonly Changed

相關(guān)文章

最新評(píng)論