Chinaunix首页 | 论坛 | 博客
  • 博客访问: 208628
  • 博文数量: 317
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 2775
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-30 12:25
文章分类

全部博文(317)

文章存档

2010年(56)

2009年(38)

2008年(223)

我的朋友

分类:

2008-11-20 15:50:14

题库内容摘自

 1. You are writing a custom dictionary. The custom-dictionary class is named MyDictionary. You need to ensure that the
dictionary is type safe. Which code segment should you use?
A. class MyDictionary : Dictionary
B. class MyDictionary : HashTable
C. class MyDictionary : IDictionary
D. class MyDictionary { ... } Dictionary t = new Dictionary();MyDictionary dictionary
= (MyDictionary)t;
Answer: A
2. You are creating a class named Age. You need to ensure that the Age class is written such that collections of Age
objects can be sorted. Which code segment should you use?
A. public class Age { public int Value; public object CompareTo(object obj) { if (obj is Age)
{ Age _age = (Age) obj; return Value.CompareTo(obj); } throw new
ArgumentException("object not an Age"); } }
B. public class Age { public int Value; public object CompareTo(int iValue) { try { return
Value.CompareTo(iValue); } catch { throw new ArgumentException ("object not an
Age"); } } }
C. public class Age : IComparable { public int Value; public int CompareTo(object obj) { if (obj is
Age) { Age _age = (Age) obj; return Value.CompareTo(_age.Value); } throw new
ArgumentException("object not an Age"); } }
D. public class Age : IComparable { public int Value; public int CompareTo(object obj) { try
{ return Value.CompareTo(((Age) obj).Value); } catch { return -1; } } }
Answer: C
3. You are creating a class to compare a specially-formatted string. The default collation comparisons do not apply. You
need to implement the IComparable interface. Which code segment should you use?
A. public class Person : IComparable{ public int CompareTo(string other){ ... }}
B. public class Person : IComparable{ public int CompareTo(object other){ ... }}
C. public class Person : IComparable{ public bool CompareTo(string other){ ... }}
D. public class Person : IComparable{ public bool CompareTo(object other){ ... }}
Answer: A

阅读(377) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~