2015級C#期末考題

答案僅供參考,歡迎交流質疑。

一、選擇題

2. The smallest unit for deployment in C# is called _______.

A.Assembly B.Namespace C.Package D.Modole

Assembly is the smallest unit for deployment and dynamic loading
the smallest unit for versioning

3. Not a valid indetifier _______.

A.@do B._main_ C.in D.πλα

 

In是C#關鍵字;可以以π、字母下劃線開頭

@+關鍵字也可以。

4. How to assign a char-type variable c with a single quote character _______.

A.c=”’” B.c=’\”’ C.c=’\’’ D.c=\’

轉義符

5. How many bytes will an int type variable usually take on 64-bit machines? _______

A.2 B.4 C.8 D.16

4字節,32位

8. “enum color:byte{Red,Yellow,Blue,Green,Purple};”, then “(Color.Yellow & Color.Blue” is  _______.

A.Color.Red B.Color.Green C.Color.Purple D.null

9. How do you format a float numble x only showing 3 numbles after the dot with an 8 character width?

A.”{1:f3}”,x B.”{1,8:f}” ,x C.”{1,8:f3}”,x D.”{0,8:f3}”,x

 

索引必須從0開始

二、判斷題

1. Multiple catch blocks are allowed after one try block.  T

2. String type variables are legal as branch values in switch structure.  T

C#string可以作爲分支判斷值

sbytebyteshortushortintuintlongulongcharstring +枚舉類型

3. File name and the main class name in that file need to be identical.   F

不一定要相同

4. All methods in an abstract class must be declared as abstract methods.  F

一個抽象類可以有抽象方法,也可以有非抽象方法

5. One method can only have one variable-length parameter.   T

6. C# allows a class to inherit from multiple classes but only one interface.  F

只能繼承一個類,但可以實現多個接口

7. A property declaration must contain both a get accessor and a set accessor.  F

可以只包含其中一個

8. Structs can be inherited. F

Struct結構體不支持繼承

9. If the parameter modified by keyword ‘out’ is not initialized within the method, it will be automatically assigned with the default value of its own type.  F

out在使用之前會將傳入參數清空,不管其原本是什麼值必須人爲爲其賦新值。

10. Defining a method with modifier ‘protected’ will only allow this class and its derived class to access it.    T

class SomeClass

    {

        //可以從任何地方訪問

        public void PublicMethod()

        {

 

        }

        //僅可以從SomeClass類型中訪問

        private void PrivateMethod()

        {

            throw new System.NotImplementedException();

        }

        //可以再SomeClass類和它的派生類中訪問

        protected void ProtectMethod()

        {

            throw new System.NotImplementedException();

        }

        //可以在同一個程序集中訪問

        internal void InternalMethod()

        {

            throw new System.NotImplementedException();

        }

        //在程序集中受保護的訪問

        protected internal void ProtectInternalMethod()

        {

            throw new System.NotImplementedException();

        }

 

        //沒有標記的成員在C#中默認爲私有的

        void SomeMethod()

        {

            throw new System.NotImplementedException();

        }

}

程序集:被編譯到同一個dllexe中的程序就是處於同一個程序集中,在不同的dllexe文件中的程序就是處於不同的程序集中。

三、填空題

1. Class modified by keyword ___sealed_____ are not allowed to inherit from.  密封類

2. To split(切分) one class definition into multiple files, you use class modifier ____partial_.

一個類被拆分到多個文件中之後,需要在每個文件中使用partial(分部)關鍵字來定義 類的不同部分

3. Class defined like “class Buffer<Element Type>{...}” is often called ____generic class___.   泛型類

4. If you are to overload operator >=, then operator ___<=____must also be overloaded manually.

==、!=><;>=<=必須成對重載

5. You use the overloaded operator __+_____to register a compatible method to a delegate variable while not offending those methods already registered.

6. Reform statement ‘b=((a is B)?(B)a:null)’ with keyword ‘as’ ______b=a as B_.

https://www.cnblogs.com/cgli/archive/2011/05/10/2041731.html

7. Assum x and y are ansigned integer type. Please reform expression ‘(x*7-y)/4’ only using left/right shifts and add/subtract operators ____x<<1-x>>2-y>>2___.

2左移1位,除2右移1

8. In array ‘int[] a={1,4,2,5,3}’, what is the value of a[a[a[2]]] ? _____2__.

9. Suppose there is a string array, now we are use Linq to Objects to query it:

string[] valleys={“Greenill”,”WilliNeer”,”Vakumy”,”Alitheir”,”NutteR”};

var Result = from v in valleys where v.EndsWith(“r”)  orderby v select v.ToLower();

please orginaze the result into oneline, use spaces to separate items.

____alitheir___ __nutter_____ ____willineer___ _______ _______

ToLower方法把字母字符轉化爲小寫;

10. Here is part of help information of csc.exe below. Please write a command to compile Main.cs with library Utils.lib to generate a console executable Program.exe.

___csc____ ____/r:Utils.lib___ ___/out:Program.exe____ Main.cs_______ _______

四、簡答題

1. What is the difference between the virtual method and the abstract method?

抽象方法是隻有方法名稱,沒有方法體(也就是沒有方法具體實現),子類必須重寫父類抽象方法;

 

           虛函數是該方法有方法體,但是子類可以覆蓋,也可不覆蓋。

 

1)虛方法有方法體,抽象方法沒有方法體。抽象方法是一種強制派生類覆蓋的方法,否則派生類將不能被實例化;

 

2)抽象方法只能在抽象類中聲明,虛方法不是;

 

3)派生類必須重寫抽象類中的抽象方法,虛方法則不必要。

2. Write down the difference between overloading and overriding.

重載某個方法是在同一個類中發生的!重寫是在子類中重寫父類中的方法。

1.override:   父類:public virtual string ToString(){return "a";}

                   子類:public override string ToString(){return "b";}

2.overload:  同一類中或父子關係類中皆可.

                   public string ToString(){return "a";}

                   public string ToString(int id){return id.ToString();}

重寫(override)是用於重寫基類的虛方法,這樣在派生類中提供一個新的方法;

 

重載(overload)是提供了一種機制, 相同函數名通過不同的返回值類型以及參數來表來區分的機制

3. Give a brief description about the difference and connect between the class and interface.(至少7個)

http://www.jb51.net/article/37971.htm

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章