C#练习题
《C#程序设计》 王晨阳
一、单选题
1、在C#中,关于继承和接口,以下说法正确的是( )。 a) C#允许多接口实现,也允许多重继承 b) C#允许多接口实现,但不允许多重继承 c) C#不允许多接口实现,但允许多重继承 d) C#不允许多接口实现,也不允许多重继承
2、以下关于C#代码的说法正确的是( )。
using System; class Test {
static void Main() {
for (int i = 1; i <= 3; i++) {
switch (i) {
case 1:
Console.Write(i.ToString()); case 2:
Console.Write((i * 2).ToString()); case 3:
Console.Write((i * 3).ToString()); } } } }
a) b) c) d)
程序将报告编译错误,提示case标签不能贯穿到另一个标签,不能运行 运行是输出149
运行时输出123246369 运行时在屏幕上没有输出
3、在ADO.NET中,下列( )组件不属于.NET数据提供程序。 a) Connection b) Command c) DataSet d) DataADapter
4、在C#中,下列代码的运行结果是( )。
using System; class Test {
public struct Point {
public int x; public int y;
public Point(int x, int y) {
this.x = x; this.y = y; } }
static void Main() {
Point p1 = new Point(100, 100); Point p2 = p1; p1.x = 200;
Console.WriteLine(\, p1.x, p2.x); } }
a)100,100 b)100,200 c)200,100 d)200,200
5、在C#中,下列代码运行后的输出结果是( )。
using System;
using System.Data; class Test {
static void Main() {
DataTable dt = new DataTable();
dt.Columns.Add(\编号\, typeof(System.Int16)); dt.Columns.Add(\成绩\, typeof(System.Int16)); for (int i = 1; i <= 3; i++) {
DataRow dr = dt.NewRow(); dr[0] = i;
dt.Rows.Add(dr); }
Console.WriteLine(dt.Columns.Count); } }
a) 1 b) 2 c) 3 d) 4
6、在ADO.NET中,下列代码的输出结果是()。
using System;
using System.Data.SqlClient; class Test {
static void Main() {
SqlConnection conn = new SqlConnection(@\
Source=localhost\\SQLEXPRESS;Initial Catalog=ADOTest;Persist Security Info=True;User ID=sa;Password=123456\);
Console.WriteLine(conn.ConnectionString); } }
a) pub b) bill
Source=localhost\\SQLEXPRESS;Initial
Catalog=ADOTest;Persist Security Info=True;User ID=sa;Password=123456
d) Northwind
7、C#的数据类型有( )。
a) 值类型和调用类型 b) 值类型和引用类型 c) 引用类型和关系类型 d) 关系类型和调用类型
8、在C#中,下列代码的运行结果是( )。
c) Data
using System; class Test {
static void ShowArrayInfo(int[] student) {
for(int i=0;i Console.Write(student[i]++); Console.Write(\); } } static void Main() { int[] student = new int[]{1,2,3,4,5}; ShowArrayInfo(student); Console.Write(\); ShowArrayInfo(student); } } a) 1 2 3 4 5 1 2 3 4 5 b) 1 2 3 4 5 2 3 4 5 6 c) 2 3 4 5 6 2 3 4 5 6 d) 2 3 4 5 6 3 4 5 6 7 9、在C#中,下列选项中哪一个是引用类型:( )。 a) enum类型 b) struct类型 c) string类型 d) int类型 10、在C#中,下列代码的运行结果是( )。 float f = 123.56F; object o = f; f = 789.123F; Console.WriteLine(\, f); Console.WriteLine(\, o); a) f=789.123 o=123.56 b) f=123.56 o=789.123 c) f=789.123 o=789.123 d) f=123.56 o=123.56 11、在C#中.假如有一个名为”MessageDelegate”的委托,下列能够正确定义一个事 件的是( )。 a) b) c) d) public delegate MessageDelegate messageEvent; public MessageDelegate messageEvent; private event MessageDelegate(mesageEvent); public event MessageDelegate messageEvent; 12、在C#中,下列代码的运行结果是( )。 using System; public delegate void BuyTicketDelegate(string num); public class Student { public event BuyTicketDelegate blEvent; public Student(string num) { blEvent += new BuyTicketDelegate(this.BuyTicket); } public void ShowNum(string num) { blEvent(num); } private void BuyTicket(string num) { Console.WriteLine(\我要买\ + num + \次车票\); } static void Main() { Console.WriteLine(\创建学生对象\); Student stu = new Student(\); Console.WriteLine(\创建完毕\); stu.ShowNum(\); } } a) 创建学生对象 创建完毕 b) 创建学生对象 我要买T1次车票 创建完毕 c) 创建学生对象 创建完毕 我要买T1次车票 d) 我要买T1次车票 创建学生对象 创建完毕 13、在C#中,下列代码的运行结果是( )。