答案仅供参考,欢迎交流质疑。
一、选择题
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可以作为分支判断值
sbyte、byte、short、ushort、int、uint、long、ulong、char、string +枚举类型
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();
}
}
程序集:被编译到同一个dll或exe中的程序就是处于同一个程序集中,在不同的dll或exe文件中的程序就是处于不同的程序集中。
三、填空题
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