2013微軟認(rèn)證考試練習(xí)題及答案(15)

字號(hào):

為大家收集整理了《2013微軟認(rèn)證考試練習(xí)題及答案(15)》供大家參考,希望對(duì)大家有所幫助?。。?BR>    第 71 題
    你寫(xiě)了一個(gè)如下的自定義異常處理類(lèi) CustomException:
    Public Class CustomException Inherits ApplicationException
    Public Shared COR_E_ARGUMENT As Int32 = &H80070057
    Public Sub New(ByVal strMessage As String)
    MyBase.New(strMessage)
    HResult = COR_E_ARGUMENT
    End Sub
    End Class
    你需要使用CustomException類(lèi)實(shí)現(xiàn)一段能夠立即讓COM調(diào)用者獲得控制權(quán)的代碼。同時(shí)能夠
    保證調(diào)用者能夠訪(fǎng)問(wèn)到錯(cuò)誤代碼。你應(yīng)該使用下面哪段代碼?
    A. Return Marshal.GetExceptionForHR( _
    CustomException.COR_E_ARGUMENT)
    B. Return CustomException.COR_E_ARGUMENT
    C. Marshal.ThrowExceptionForHR( _
    CustomException.COR_E_ARGUMENT)
    D. Throw New CustomException("Argument is out of bounds")
    答案: D
    第 72 題
    你正在寫(xiě)一個(gè)返回值為ArrayList對(duì)象al的方法。你需要保證對(duì)ArrayList的修改是線(xiàn)程安全的。你
    應(yīng)該使用下面哪段代碼?
    A. ArrayList al = new ArrayList();lock (al.SyncRoot){
    return al;}
    B. ArrayList al = new ArrayList();lock (al.SyncRoot.GetType()){
    return al;}
    C. ArrayList al = new ArrayList();Monitor.Enter(al);Monitor.Exit(al);return al;
    D. ArrayList al = new ArrayList();ArrayList sync_al = ArrayList.Synchronized(al);return sync_al;
    答案: D
    第 73 題
    你正在開(kāi)發(fā)一個(gè)實(shí)現(xiàn)電子問(wèn)卷的應(yīng)用。問(wèn)卷共有 25 個(gè)答案為 true 或 false 的問(wèn)題。你需要
    完成如下任務(wù):1)初始化每個(gè)問(wèn)題答案為 true;
    2)每個(gè)問(wèn)題答案使用最小的內(nèi)存。
    你應(yīng)該選擇使用那鐘方式進(jìn)行存儲(chǔ)答案?
    A. BitVector32 answers = new BitVector32(1);
    B. BitVector32 answers = new BitVector32(-1);
    C. BitArray answers = new BitArray(1);
    D. BitArray answers = new BitArray(-1);
    答案: B
    第 74 題
    你需要讀取文件 Message.txt 的完整內(nèi)容到一個(gè)字符串變量中。你應(yīng)該使用哪段代碼?
    A. string result = null;StreamReader reader = new StreamReader("Message.txt");result =
    reader.Read().ToString();
    B. string result = null;StreamReader reader = new StreamReader("Message.txt");result =
    reader.ReadToEnd();
    C. string result = string.Empty;StreamReader reader = new StreamReader("Message.txt");
    while
    (!reader.EndOfStream) {
    result += reader.ToString();}
    D. string result = null;StreamReader reader = new StreamReader("Message.txt");result =
    reader.ReadLine();
    答案: B
    第 75 題
    你正在創(chuàng)建一個(gè)名為 Age 的類(lèi)。你需要保證 Age 對(duì)象的集合能夠被排序。你應(yīng)該使用下面哪段
    代碼?
    A. public class Age {
    public int Value;
    public object CompareTo(object obj) {
    if (obj is Age) {
    Age_age = (Age) obj;
    return Value.ComapreTo(obj);
    }
    throw new ArgumentException("object not an Age");
    }
    }
    B. public class Age {
    public int Value;
    public object CompareTo(int iValue) {
    try {
    return Value.ComapreTo(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.ComapreTo(_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.ComapreTo(((Age) obj).Value);
    } catch {
    return -1;
    }
    }
    }
    答案: C