测测你对C#概念性的东西了解多少
2012-02-09 13:41
274 查看
1.在C#中,关于ArrayList和Hashtable的说法,错误的是()
A ArrayList通过索引访问集合元素,Hashtable通过Key访问集合元素
B ArrayList和Hashtable 都可以用RemoveAt方法删除其中的元素
C ArrayList和Hashtable获取集合中的元素时,都需要类型转换
D 在同一个ArrayList或者Hashtable中,可以存储不同类型的元素
2.下面关于泛型集合List<String> list = new List<String>()的操作代码错误的是()
A list.Remove(0)
B list.RemoveAt("王五")
C string name = list[0]
D string name = list["李四"]
3.下面关于泛型集合Dictionary<String, Student> dict = new Dictionary<string,Student>()
A dict.RemoveAt(0)
B foreach(Diction<string,Student> stu in dict){}
C foreach(Student stu in Keys){}
D foreach(Student stu in Values){}
4.在C#中,关于List<T>和Dictionary<K,V>的说法,正确的是()
A List<T>和Dictionary<K,V>都可以循环遍历整个元素对象
B 获取元素时,List<T>需要类型转换,Dictionary<K,V>不需要
C List<T>通过索引访问集合元素,Dictionary<K,V>通过Key访问集合元素
D 在同一个List<T>和Dictionary<K,V>中,可以存储不同类型的元素
5.分析下面一段程序,下列代码初始化对象错误的是()
public class Table
{
private int width;
private int height;
private string id;
public Table(int width,int height, string id)
{
this.width = width;
this.height = height;
this.id = id;
}
public Table(int height)
{
this.height = height;
}
public Table(int height,int width)
{
this.height = height;
this.width = width;
}
}
A Table myTable = new Table(10,10, "table")
B Table myTable = new Table(10,10)
C Table myTable = new Table(10)
D Table myTable = new Table()
6.指出下面代码的不合理之处,并予以改正
static void Main(string [] args)
{
Student stu1 = new Student("张三");
Student stu2 = new Student("李四");
Student stu3 = new Student("王五");
Dictionary<String,Student> dict = new Dictionary<String,Student>();
dict.Add(stu1.name,stu1);
dict.Add(stu2.name,stu2);
dict.Add(stu3.name,stu3);
//删除第二个元素
dict.RemoveAt(1);
//获取第一个元素
Student student = (Student)dict[stu1.name];
//遍历整个集合
foreach(Student stu in dict.Values)
{
Student myStudent = dict.Value;
}
}
1.B
2.ABD
3.CD
4.AC
5.D
6. 错误的是 //删除第二个元素 dict.RemoveAt(1); 是根据Key值来删除元素的,而不是根据索引删除元素 //获取第一个元素 Student student = (Student)dict[stu1.name]; 泛型不需要类型转换吧?
A ArrayList通过索引访问集合元素,Hashtable通过Key访问集合元素
B ArrayList和Hashtable 都可以用RemoveAt方法删除其中的元素
C ArrayList和Hashtable获取集合中的元素时,都需要类型转换
D 在同一个ArrayList或者Hashtable中,可以存储不同类型的元素
2.下面关于泛型集合List<String> list = new List<String>()的操作代码错误的是()
A list.Remove(0)
B list.RemoveAt("王五")
C string name = list[0]
D string name = list["李四"]
3.下面关于泛型集合Dictionary<String, Student> dict = new Dictionary<string,Student>()
A dict.RemoveAt(0)
B foreach(Diction<string,Student> stu in dict){}
C foreach(Student stu in Keys){}
D foreach(Student stu in Values){}
4.在C#中,关于List<T>和Dictionary<K,V>的说法,正确的是()
A List<T>和Dictionary<K,V>都可以循环遍历整个元素对象
B 获取元素时,List<T>需要类型转换,Dictionary<K,V>不需要
C List<T>通过索引访问集合元素,Dictionary<K,V>通过Key访问集合元素
D 在同一个List<T>和Dictionary<K,V>中,可以存储不同类型的元素
5.分析下面一段程序,下列代码初始化对象错误的是()
public class Table
{
private int width;
private int height;
private string id;
public Table(int width,int height, string id)
{
this.width = width;
this.height = height;
this.id = id;
}
public Table(int height)
{
this.height = height;
}
public Table(int height,int width)
{
this.height = height;
this.width = width;
}
}
A Table myTable = new Table(10,10, "table")
B Table myTable = new Table(10,10)
C Table myTable = new Table(10)
D Table myTable = new Table()
6.指出下面代码的不合理之处,并予以改正
static void Main(string [] args)
{
Student stu1 = new Student("张三");
Student stu2 = new Student("李四");
Student stu3 = new Student("王五");
Dictionary<String,Student> dict = new Dictionary<String,Student>();
dict.Add(stu1.name,stu1);
dict.Add(stu2.name,stu2);
dict.Add(stu3.name,stu3);
//删除第二个元素
dict.RemoveAt(1);
//获取第一个元素
Student student = (Student)dict[stu1.name];
//遍历整个集合
foreach(Student stu in dict.Values)
{
Student myStudent = dict.Value;
}
}
1.B
2.ABD
3.CD
4.AC
5.D
6. 错误的是 //删除第二个元素 dict.RemoveAt(1); 是根据Key值来删除元素的,而不是根据索引删除元素 //获取第一个元素 Student student = (Student)dict[stu1.name]; 泛型不需要类型转换吧?
相关文章推荐
- C# 创建、部署和调用WebService的简单示例 webservice 可以用于分布式应用程序之间的交互,和不同程序之间的交互。 概念性的东西就不说太多,下面开始创建一个简单的webservi
- 一些C#概念性东西
- C# .NET ASP.NET 其中关系你了解多少
- C#目前想要了解请楚的东西
- C# 当前目录你了解多少
- 一句话解释c#中的特性,你了解多少
- 关于机器学习算法 你需要了解的东西看看你了解多少
- 关于机器学习算法 你需要了解的东西看看你了解多少
- C# D3D中2D的使用,做小游戏。。。。半年前写的东西了,拿出来分享,现在看来代码写的乱七八糟的,将就一下吧。。。
- 如果你的简历上面写“熟悉/了解C#”,那么你就应该能够回答下面的这些基础问
- 【转】10分钟了解设计模式(C#)
- C#.NET常见问题(FAQ)-list比数组效率低多少
- Web开发中需要了解的东西
- 挖一挖C#中那些我们不常用的东西之系列(3)——StackTrace,Trim
- JavaScript中三个等号和两个等号你了解多少
- 关于网络层你了解多少
- C#反射中最最最基本的东西
- 【Qt】测测你对Qt的了解–Qt工具知多少
- 看完C#写点东西
- 找工作的你需要了解和准备的东西