大学MOOC 使用C#开发数据库应用程序(濮阳职业技术学院)1450441222 最新慕课完整章节测试答案
第七周
第七周 单元测试
1、单选题:
在Array类中,可以对一维数组中的元素进行排序的方法是( )
选项:
A: Sort()
B: Clear()
C: Copy()
D: Reverse()
答案: 【 Sort() 】
2、单选题:
在Array类中,可以对一维数组中的元素查找的方法是( )
选项:
A: Sort()
B: BinarySearch()
C: Convert()
D: Index()
答案: 【 BinarySearch()】
3、单选题:
假定一个10行20列的二维整型数组,下列哪个定义语句是正确的
选项:
A: int[]arr = new int[10,20]
B: int[]arr = int new[10,20]
C: int[,]arr = new int[10,20]
D: int[,]arr = new int[20;10]
答案: 【 int[,]arr = new int[10,20]】
4、单选题:
下面程序段输出的结果是public class Test{ string[] names = { "a", "b", "c", "d" }; public IEnumerator<string> GetEnumerator() { for (int i = 0; i < 4; i++) yield return names[i]; } static void Main(string[] args) { Test titles = new Test(); IEnumerator ie= titles.GetEnumerator() ; ie.MoveNext(); System.Console.Write(ie.Current); } }
选项:
A: a
B: b
C: d
D: [空]
答案: 【 a】
5、单选题:
选择下列代码的运行结果class A{ public Hashtable studentlist = new Hashtable(); public int this[string name] { get { return (int)studentlist[name]; } set { studentlist[name] = value; } } static void Main(string[] args) { A a = new A(); a[10] = "张三"; Console.WriteLine(a[10]); } }
选项:
A: 10
B: 张三
C: 0
D: 无法运行
答案: 【 无法运行】
6、单选题:
如果要使在实例化泛型类时使用的类型参数限定为值类型,则在泛型类型参数约束应该是:
选项:
A: new
B: struct
C: class
D: Base
答案: 【 struct】
7、单选题:
若有如下定义class BaseNodeMultiple<T, U> { }则下面定义错误的是
选项:
A: class Node4<T> : BaseNodeMultiple<T, int> { }
B: class Node5<T, U> : BaseNodeMultiple<T, U> { }
C: class Node6<T> : BaseNodeMultiple<T, U> { }
D: class Node6<T,U> : BaseNodeMultiple<int, int> { }
答案: 【 class Node6<T> : BaseNodeMultiple<T, U> { }】
8、单选题:
阅读下面程序段class Student : Person{ public override string ToString() { return ID + "t" + Name; } static void Main() { Student s = new Student(); s.ID = 1; s.Name = "JSON"; PromptName<Student>(s); } }public class Person{ public int ID { get; set; } public string Name { get; set; } public static void PromptName<T>(T t) where T : Person { Console.WriteLine(t); } }程序运行结果:
选项:
A: 1 JSON
B: Student
C: Person
D: 出错,约束条件受限
答案: 【 1 JSON】
9、单选题:
阅读下面的程序 public class Person { public string Name { get; set; } public Person( string name) { Name = name; } public override string ToString() { return Name; } static void Main(string[] args) { int[] A1 = new int[] { 1, 2 }; int[] A2 = (int[])A1.Clone(); int[] A3 = new int[2]; Person[] p1 = new Person[] { new Person("A"), new Person("B") }; Person[] p2 = (Person[])p1.Clone(); Person[] p3 = new Person[2]; Array.Copy(p1, p3, 1); Array.Copy(A1, A3, 1); p2[0].Name = "C"; A2[0] = 3; Console.WriteLine("{0},{1},{2}", p1[0], p2[0],p3[0]); Console.WriteLine("{0},{1},{2}", A1[0], A2[0], A3[0]); }}程序运行的结果是:
选项:
A: A,B,C1,2,3
B: C,B,C1,2,1
C: C,C,C1,1,1
D: C,C,C1,3,1
答案: 【 C,C,C1,3,1】
10、单选题:
声明一个数组:int[,] arr = new int[3,5],这个数组内包含( )个元素
选项:
A: 5
B: 35
C: 15
D: 3
答案: 【 15】
11、单选题:
下面程序运行的结果是() class test { static void Main(string[] args) { Queue Q = new Queue(); Stack S = new Stack(); for (int i = 1; i <= 10; i++) Q.Enqueue(i); for (int i= 1;i<=10;i++) if (i%2==0) S.Push(Q.Dequeue()); for (int i = 0; i < S.Count; i++) Console.Write("{0},", S.Pop()); } } A、2,4,6,8,10,B、10,9,8,C、9,7,5,3,1,D、5,4,3答案: D2、下面程序运行的结果是()public class test{ string[] names = { "a", "b", "c", "d","e" }; public IEnumerator<string> GetEnumerator() { for (int i = 0; i < 5; i++) yield return names[2*i+1]; } static void Main(string[] args) { test ts = new test(); foreach (string s in ts) Console.Write("{0},",s); } }
选项:
A: a,b,c,d,e
B: 0,1,3
C: a,c,e
D: b,d
答案: 【 b,d】
12、单选题:
下面程序运行的结果是() class A{ public Hashtable studentlist = new Hashtable(); public string this[string name] { get { return (string) studentlist[name]; } set { studentlist[name] = value; } } static void Main(string[] args) { A a = new A(); a.studentlist.Add("1","2"); a["B"] = "A"; foreach (String e in a.studentlist.Values) Console.Write("{0},",e); }}
选项:
A: 1,2
B: B,A
C: 1,B
D: 2,A
答案: 【 2,A】
13、单选题:
在C#中,使用( )关键字创建数组的对象
选项:
A: create
B: 无
C: new
D: array
答案: 【 new】
14、单选题:
在C#中,下列代码的运行结果是( )。public class Test{ static void Main(String[] args) { int[] num = new int[5]{1,3,2,0,0}; Array.Reverse(num); foreach(int i in num) { Console.Write(i); } }}
选项:
A: 00123
B: 12300
C: 00132
D: 00231
答案: 【 00231】
15、单选题:
在C#中,下列代码运行结果是( )。class A{static void Main() { int[] num=new int[]{1,3,5}; ArrayList arr = new ArrayList(); for (int i = 0; i < num.Length; i++) { arr.Insert(i,num[i]); } arr.Insert(1, 4); Console.Write(arr[2]);}}
选项:
A: 1
B: 3
C: 4
D: 5
答案: 【 3】
16、单选题:
在C#中,如果要将数组作为一个方法的参数,则传递的是( )
选项:
A: 数组中的所有元素
B: 数组的第一个元素
C: 对象的引用
D: 以上皆非
答案: 【 对象的引用】
17、单选题:
下面程序运行的结果是: public class test{ private ArrayList Names = new ArrayList(); public test(string[] names) { foreach (string name in names) this.Names.Add(name); } public string this[int index] { get { return Names[Names.Count - index].ToString(); } } static void Main() { String[] names = new string[] { "A", "B", "C", "D" }; test t = new test(names); Console.WriteLine(t[3]); } }}
选项:
A: A
B: B
C: C
D: D
答案: 【 B】
18、单选题:
在C#中,下列代码的运行结果是( )。class A{static void Main() { int[] num = new int[] { 1, 2, 3, 4, 5 }; ArrayList arr = new ArrayList(); for (int i = 0; i < num.Length; i++) { arr.Add(num[i]); } arr.Remove(arr[2]); Console.Write(arr[2]);}}
选项:
A: 1
B: 2
C: 3
D: 4
答案: 【 4】
19、多选题:
有下面类的定义class BaseNodeGeneric<T> { }下面代码正确的是:
选项:
A: class Node1<T> : BaseNodeGeneric<int> { }/
B: class Node2 : BaseNodeGeneric<T> { }
C: class Node3 : T { }
D: class Node4 : BaseNodeGeneric<int> { }
答案: 【 class Node1<T> : BaseNodeGeneric<int> { }/ ;
class Node4 : BaseNodeGeneric<int> { }】
20、多选题:
包含yield语句的方法或属性是迭代器,迭代器的返回值必须是
选项:
A: IEnumerable
B: IEnumerable<T>
C: IEnumerator
D: IEnumerator<T>
答案: 【 IEnumerable;
IEnumerable<T>;
IEnumerator;
IEnumerator<T>】
21、判断题:
在定义泛型类时,可以对在实例化泛型类时用于类型参数的类型种类施加限制。
选项:
A: 正确
B: 错误
答案: 【 正确】
22、判断题:
数组是值类,所以将一个数组变量赋予另一个数组变量,会具有各自不同的存储空间。
选项:
A: 正确
B: 错误
答案: 【 错误】
23、判断题:
数组和集合类要声明元素的类型。
选项:
A: 正确
B: 错误
答案: 【 错误】
24、判断题:
̴
