C#习题练习(1-6章)
1. 在 Visual Studio.NET窗口中,在__________窗口中可以察看当前项目的类和类型的层次信息? (B) A.解决方案资源管理器 B.类视图 C.资源视图 D.属性
2. C#中每个 int 类型的变量占用_______个字节的内存?(C) A.1 B.2 C.4 D.8
3. 在 C#中,表示一个字符串的变量应使用以下哪条语句定义? (B) A.CString str; B.string str;
C.Dim str as string D.char * str;
4. 在 C#编制的财务程序中,需要创建一个存储流动资金金额的临时变量,则应使用下列哪条语句? (A)
A.decimal theMoney; B.int theMoney; C.string theMoney;
D.Dim theMoney as double
5. C#中,新建一字符串变量 str,并将字符串\保存到串中,则应该使用下列哪条语句? (A)
A.string str = \B.string str = \C.string str(\D.string str(\
6.C#中 MyClass 为一自定义类,其中有以下方法定义: public void Hello(){?}
使用以下语句创 建了该类的对象,并使变量 obj 引用该对象,那么,访问类MyClass的Hello方法正确的是:(A)
MyClass obj = new MyClass(); A.obj.Hello(); B.obj::Hello(); C.MyClass.Hello(); D.MyClass::Hello();
7. 分析下列 C#语句,注意类 MyClass 没有访问修饰符: namespace ClassLibrary1 {
class MyClass {
public class subclass { int i; } }
}
若必须为类 MyClass 添加访问修饰符,并使 MyClass 的可访问域保持不变,则应选择 _________?(D) A.private B.protected C.internal D.public
8. 分析下列程序: public class class4 {
private string _sData = \
public string sData{set{_sData = value;}} }
在 Main 函数中,在成功创建该类的对象 obj 后,下列哪些语句是合法的? (A) A.obj.sData = \B.Console.WriteLine(obj.sData); C.obj._sData = 100; D.obj.set(obj.sData);
9. 分析下列程序中类 MyClass 的定义 class BaseClass { public int i; } class MyClass:BaseClass { public new int i;}
则下列语句在 Console 上的输出为_______. (D) MyClass y = new MyClass(); BaseClass x = y; x.i = 100;
Console.WriteLine(\提示:注意类 MyClass 中的 new 关键字) A.0, 0 B.100, 100 C.0, 100 D.100, 0
10. 在定义类时,如果希望类的某个方法能够在派生类中进一步进行改进,以处理不同的派生类的需要,则应将该方法声明成____?(C) A.sealed 方法 B.public 方法 C.virtual 方法 D.override 方法
11. 类 MyClass 中有下列方法定义:
public void testParams(params int[] arr) { Console.Write (\使用 Params 参数!\
public void testParams(int x,int y)
{ Console.Write (\使用两个整型参数!\
请问上述方法重载有无二义性?若没有,则下列语句的输出为_______. (B) MyClass x = new MyClass(); x.testParams(0); x.testParams(0,1); x.testParams(0,1,2); A.有语义二义性;
B.使用 Params 参数!使用两个整型参数!使用 Params 参数! C.使用 Params 参数!使用 Params 参数!使用 Params 参数! D.使用 Params 参数!使用两个整型参数!使用两个整型参数!
12. C#程序中,可使用 try..catch 机制来处理程序出现的_____错误?(B) A.语法 B.运行 C.逻辑 D.拼写
13. C#中,在方法 MyFunc 内部的 try..catch 语句中,如果在 try 代码块中发生异常,并且在当前的所有 catch 块中都没有找到合适的 catch 块,则(D) A.NET 运行时忽略该异常
B.NET 运行时马上强制退出该程序
C.NET 运行时继续在 MyFunc 的调用堆栈中查找提供该异常处理的过程 D.NET 抛出一个新的“异常处理未找到”的异常
14. 在 C#中,下列哪条语句能创建一个具有 3 个初始值为\的元素的字符串数组? (C) A.string StrList[3](\
B.string[3] StrList = {\C.string[] StrList = {\D.string[] StrList = new string[3];
15. 下列语句创建了多少个 string 对象? (D) string[,] strArray = new string[3][4]; A.0 B.3 C.4 D.12
16. 接口 Animal 定义如下: public interface Animal { void Move(); }
则下列抽象类的定义中,哪些是不合法的? (D)
A.abstract class Cat: Animal { abstract public void Move(); } B.abstract class Cat:Animal{virtual public void Move(){ Console.Write(Console.Write(\C.abstract class Cat: Animal { public void Move(){Console.Write(Console.Write(\D.abstract class Cat: Animal { public void Eat(){Console.Write(Console.Write(\
17. 关于结构类型,下列说法哪些是正确的? (A) A.结构是值类型
B.结构中不允许定义带参数的实例构造函数; C.结构中不允许定义析构函数
D.结构中可以定义成员方法,但是方法内不能使用 this 指针
18. 下列语句的输出是________? (B) double MyDouble = 123456789;
Console.WriteLine(\A.$123,456,789.00 B.1.234568E+008 C.123,456,789.00
19.已知在某 Windows Form 应用程序中,主窗口类为 Form1,程序入口为静态方法 From1.Main?如下所示:
public class Form1 : System.Windows.Forms.Form {
//其他代码 static void Main() {
//在此添加合适代码 } } 则在 Main 方法中打开主窗口的正确代码是: (A) A.Application.Run(new Form1()); B.Application.Open(new Form1()); C.(new Form1()).Open(); D.(new Form1()).Run();
20. 用鼠标右击一个控件时出现的菜单一般称为: (C) A.主菜单 B.菜单项 C.快捷菜单 D.子菜单
21. 变量 openFileDialog1 引用一个 OpenFileDialog 对象?为检查用户在退出对话框时是否 单击了“打开”按钮,应检查 openFileDialog1.ShowDialog()的返回值是否等于_______;(A)
A.DialogResult.OK B.DialogResult.Yes C.DialogResult.No D.DialogResult.Cancel
22. C#程序中,为使变量 myForm 引用的窗体对象显示为对话框,必须: (A) A.使用 myForm.ShowDailog 方法显示对话框 B.将 myForm 对象的 isDialog 属性设为 true
C.将 myForm 对象的 FormBorderStyle 枚举属性设置为 FixedDialog D.将变量 myForm 改为引用 System.Windows.Dialog 类的对象
23. Windows Form 应用程序中,要求下压按钮控件Button1 有以下特性:正常情况下,该 按钮是扁平的,当鼠标指针移动到它上面时,按钮升高?那么,在程序中,属性 Button1.FlatStyle 的值应设定为: (B) A.System.Windows.Forms.FlatStyle.Flat
B.System.Windows.Forms.FlatStyle.Popup C.System.Windows.Forms.FlatStyle.Standard D.System.Windows.Forms.FlatStyle.System
24. 在类的定义中,类的__________描述了该类的对象的行为特征?(A) A.类名 B.方法
C.所属的名字空间 D.私有域
25. 以下类 MyClass 的属性 count 属于_____属性. (A) class MyClass {
int i; int count
{
get{ return i;} } } A.只读 B.只写 C.可读写
D.不可读不可写
26. 类 MyClass 中,下列哪条语句定义了一个只读的属性 Count? (B) A.private int Count;
B.private int count; public int Count{ get{return count;} } C.public readonly int Count; D.public readonly int Count
{ get{ return count;} set{count = value;} } 27. C#中的类型 float 对应.NET 类库中的(A) A.System.Single B.System.Double C.System.Int32 D.System.Int64
28. 判断下列类 MyClass 的定义中哪些是合法的抽象类? (A)抽象成员不能是私有的 A.abstract class MyClass
{ public abstract int getCount(); } B.abstract class MyClass
{ abstract int getCount(); } C.private abstract class MyClass { abstract int getCount(); } D.sealed abstract class MyClass { abstract int getCount(); }
29. 已知接口 IHello 和类 Base?MyClass 的定义如下 interface IHello { void Hello(); }