北航软院2014级C#期末考试部分考题解答
博主注:本渣渣水平有限,文中若有不对的地方敬请指出,谢谢。
本文中大部分图片来自老师的PPT,感谢邵老师,想要的可以点击右边QQ联系我:)
一、选择
6.Which of the following is wrong?
①Abstract class could contain non abstract method//抽象类可能没有抽象方法
②A class containing abstract method must be a abstract class.//含有抽象方法的类一定是抽象类
③An abstract class cannot be instantiated.//不能实例化
④An abstract class can be sealed class.
解答:基础知识
7. Which of the following is right use of generic?
①List<int> f = new List<int>()
②List<int> f = new List()
③List f = new List()
④List<int> f = new List<int>
解答:通用类的使用方法
8.Which of the statements is correct to declare a two-dimensional array in C#?
①int[][] a
②int a[][]
③int[2]a
④int a[2]
解答:创建数组
//一维 int[] a = new int[3]; int[] b = new int[] { 3, 4, 5 }; int[] c = { 3, 4, 5 }; //非矩阵二维数组 //int wrong1[1][2];//错误 int[][] aa = new int[2][];// array of references to other arrays aa[0] = new int[] { 1, 2, 3 };// cannot be initialized directly aa[1] = new int[] { 4, 5, 6 }; //矩阵二维数组 int[,] aaa = new int[2, 3];// block matrix int[,] bbb = { { 1, 2, 3 }, { 4, 5, 6 } };// can be initialized directly int[,,] ccc = new int[2, 4, 2];
9.A property’s ______ accessor enable a client to modify the value of the instance variable associated with the property.
①base ②this ③get ④set
10. Only the methods that are declared as ______ can be overridden in subclass.
①abstract ②virtual ③new ④override
15. In .NET Framework class library, all multithread application related classes are in which following namespace?
①System.SysThread
②System.Thread
③System.Threading
④NetException
17. In C# variables confined by which of the following modifies can only be accessed by the current assembly?
①public ②protected ③internal ④private
解答:
17.Which of the following is the right output?
using System; class A { struct Student { public int age; public string name; public Student(int age,string name) { this.age = age; this.name = name; } }; static void Main(string[] args) { Student stu1 = new Student(18, " Tom"); Student stu2 = new Student(24, " Jerry"); stu2 = stu1; stu1.age = 30; stu1.name = "Jerry"; Console.Write(stu2.age); Console.Write(stu2.name); Console.ReadKey(); } }
①18 Tom ②18 Jerry ③30 Jerry ④30 Tom
解答:结构体实值类型,赋值之后就把<18,Tom>给了stu2,不管你stu1怎么变,与stu2无关。
18. Which of the following results is the right output?
ArrayList arr = new ArrayList();
int[] num = { 1, 3, 5 };
for (int i = 0; i < num.Length; i++)
{
arr.Add(num[i]);
}
arr.Insert(1, 4);
Console.WriteLine(arr[2]);
①1 ②3 ③4 ④5
解答:了解insert函数的定义就知道啦。
19.Which of the following description is true about the keyword “ref”?
①”ref” only passes values from caller(调用者)to callee(被调者)
②”ref” only passes values from the callee to caller
③”ref” must be initialized before its method is called.//方法被调用之前,必须初始化
④None of above
解答:VS爸爸最厉害~
20.Which of the following description about constants is true?
①Declare the constants with the keyword “static”
②The constants must be initialized when declaring.
③Constants can be assigned repeatedly.
④Constants can be declared first and assigned later.
解答:常量的基本知识
二、判断
1.Only one method can be called using a delegate.
解答:(F)
2.If no constructor was declared in a class, the compiler generates default constructor which has no parameter.
解答:(T)可能类不是亲生的吧。(PPT115页)
3.All methods in an abstract class must be declared as abstract methods.
解答:(F)没这个道理!道理在下面(PPT146页):
4.If a base class declares an abstract method, a derived class must implement that method.
解答:(F)派生类确实要实现所有抽象方法,但是派生类也可以继续是抽象的呀!,这样就不用管实不实现了。
5.Sizeof can be applied to reference types.
解答:(F)
6.One file could have multiple namespaces.
解答:(T)PPT197页
7.Nested types can be interfaces and delegates.
解答:(T)PPT131页
8.If a method is marked as Protected, it will be able to access in the derived class.
解答:(T)
9.Sizeof can be applied to reference types.(重复了啊啊啊)
10.If a base declares an abstract method, a derived class should implement that method.(握草一个should一个must,搞什么鬼!)
三、填空
1.In C#, the type System.Int32 map to keyword _____int______
解答:这个还真没仔细看过,万一考个偏的怎么办。
2.In C#, if you want to change a thread’s state from suspended into running, what method you should call? Resume
3.The following class is often called _____Generic______
class Buffer<Element> {
private Element[] data;
public Buffer( int size ) {…}
public void Put(Element x) {…}
public Element Get() {…}
}
4.Every interface member must be __implemented___ or ___inherited____ from a base class.
解答:接口的成员要么自己定义要么继承自父类。
接口不能包含常量、字段、操作符、构造函数、析构函数、任何静态成员、方法的实现;
5.??????
6.Write the output.
static void Main() { String[] cities = {"London","Vienna","Paris","Linz", "Brussels"}; //using Linq to Objects IEnumerable<string> result = from c in cities where c.StartsWith("L") orderby c select c.ToUpper(); foreach (string s in result) Console.WriteLine(s); Console.ReadKey(); }
解答:原题目好像并不能输出什么啊,改了一下题目,他的意思应该是是要输出result内容。结果如下:
LINZ
LONDON
7. Fill in the blank
using System; class Program { static void Main() { Myclass m = new Myclass(); int[] s = new int[5] { 1, 2, 3, 4, 5 }; int smax, smin; m.MaxMin(s, out smax, out smin); Console.WriteLine("{0} {1}", smax, smin); Console.ReadKey(); } } class Myclass { public void MaxMin(int[] a, out int max, out int min) { max = min = a[0]; for (int i = 1; i < a.Length; i++) { if (a[i] > max) max = a[i]; if (a[i] < min) min = a[i]; } } }
解答:out的用法(默默在MaxMin前面加了一个public)。
8.Write the output.
delegate void Notifier (string sender); void SayHello(string sender) { Console.WriteLine("Hello from " + sender); } void SayGoodBye(string sender) { Console.WriteLine("Goodbye from " + sender); } Notifier greetings; greetings = SayHello; greetings += SayGoodBye; greetings("John"); greetings -= SayHello; greetings("John");
解答:代理的基本用法。输出结果:
Hello from John
Goodbye from John
Goodbye from John
9.Write the result of array A.
static void Main() { int[] A = new int[5] { 1, 2, 3, 4, 5 }; Object[] B = new Object[5] { 6, 7, 8, 9, 10 }; Array.Copy(A, B, 2); foreach (int x in A) Console.WriteLine(x);
foreach (int x in B) Console.WriteLine(x);
Console.ReadKey();
}
解答:考察Copy的用法。这里面A没有变哦,反倒是B变成了{1,2,8,9,10}
输出结果(数组A内容):
10.Please fill in the blanks.
namespace test { public delegate void OnDBOperate(); public class UserControlBase : System.Windows.Forms.UserControl { public event OnDBOperate OnNew; private void toolbar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { if (e.Button.Equals(BtnNew)) { //Please write code to call OnNew events if (OnNew != null) OnNew(); } } } }
四、简答
1.What is the difference between virtual method and the abstract method?
解答:抽象方法是只有定义、没有实际方法体的函数,它只能在抽象类中出现,并且在子类中必须重写;抽象方法是一种强制派生类覆盖的方法,必须被派生类覆写的方法,否则派生类将不能被实例化。抽象方法是可以看成是没有实现体的虚方法,如果类中包含抽象方法,那么类就必须定义为抽象类,不论是否还包含其它一般方法。
虚方法则有自己的函数体,已经提供了函数实现,而且允许在子类中重写或覆盖。虚方法可以不在派生类中重写。
2.C# uses different modifiers to confine the data security. There are 5 different modifiers. Please list out each of them and explain their security level.
解答:简单叙述了一下。
public 公有访问。不受任何限制。
private 私有访问。只限于本类成员访问,子类,实例都不能访问。
protected 保护访问。只限于本类和子类访问,实例不能访问。
internal 内部访问。只限于本项目内访问,其他不能访问。
protected internal 内部保护访问。只限于本项目或是子类访问,其他不能访问。
3.What are the difference between the value type and the reference type.
Value Type |
Reference Type |
|
|
|
|
|
|
解答:去年原题,看他这意思是要写三个对比QAQ。
值类型直接存储其值,值类型部署在栈上,初始化为0,false,'\0'等。
而引用类型存储对其值的引用,引用类型部署在托管堆上,初始化为null。
具体详解:http://blog.csdn.net/qiaoquan3/article/details/51202926
4. Write down the differences between Overloading and Overriding?
解答:陈年老题了。
5.Please give a brief description about the difference and connection between the class and interface.
Class |
Interface |
|
|
|
|
|
|
|
|
解答:前年原题qwq
对了,看到一篇讲了C#各种对比的帖子,分享给你们,可以参考:http://www.jb51.net/article/37971.htm
最后,大家加油呀,祝下午考试顺利~
作者: AlvinZH
出处: http://www.cnblogs.com/AlvinZH/
本文版权归作者AlvinZH和博客园所有,欢迎转载和商用,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。