第 1 題
你正在開發(fā)一個自定義事件處理去自動打印所有打開的文檔。事件處理可以指定要打印的份
數(shù)。為此,你需要開發(fā)一個傳遞給事件處理程序的自定義事件參數(shù)類,你應(yīng)該使用下面那個
代碼段?
A. public class PrintingArgs {
private int copies;
public PrintingArgs(int numberOfCopies) {
this.copies = numberOfCopies;
}
public int Copies {
get { return this.copies; }
}}
B. public class PrintingArgs : EventArgs {
private int copies;
public PrintingArgs(int numberOfCopies) {
this.copies = numberOfCopies;
}
public int Copies {
get { return this.copies; }
}}
C. public class PrintingArgs {
private EventArgs eventArgs;
public PrintingArgs(EventArgs ea) {
this.eventArgs = ea;
}public EventArgs Args {get { return eventArgs; }}}
D. public class PrintingArgs : EventArgs {
private int copies;}
答案: B
第 2 題
你使用反射(Reflection)來獲得方法 MyMethod 的信息。你需要獲取 MyMethod 方法是否在
派生類中可以訪問,你應(yīng)該如何做?
A. 訪問MethodInfo 的IsAssembly 屬性。
B. 訪問MethodInfo 的IsVirtual屬性。
C. 訪問MethodInfo 的IsStatic屬性。
D. 訪問MethodInfo 的IsFamily屬性。
答案: D
第 3 題
你正在創(chuàng)建一個使用非托管資源的類。這個類引用了使用托管資源的對象。你需要確保使用
這個類的用戶在不需要類實例的時候能夠夠釋放資源。你應(yīng)該做那三個工作?
(每個答案是解決方案的一部分)
A. 定義一個從WeakReference 繼承的類。
B. 定義一個實現(xiàn)IDisposable 接口的類。
C. 創(chuàng)建一個類析構(gòu)函數(shù),調(diào)用其它對象的方法去釋放托管資源。
D. 創(chuàng)建一個類析構(gòu)函數(shù),釋放非托管資源
E. 創(chuàng)建一個Dispose方法,調(diào)用System.GC.Collect 強制垃圾回收。
F. 創(chuàng)建一個Dispose方法,釋放非托管資源并且調(diào)用其它對象的方法釋放托管資源。
答案: B, D, F
第4 題
你正對一個應(yīng)用進行調(diào)試。你需要找到引起異常的代碼行。請問,Exception 類的哪個屬性
能達到這個目的?
A. Data
B. Message
C. StackTrace
D. Source
答案: C
第 5 題
你正在測試一個新開發(fā)的方法 PersistToDB。這個方法接收一個類型為 EventLogEntry 的參數(shù),
方法沒有返回值。你需要創(chuàng)建一段代碼來幫助你測試這個方法。這段代碼必須從本地計算機的應(yīng)
用日志讀取日志項然后傳遞日志項給 PersistToDB 方法。要求,傳遞到 PersistToDB 方法的日
志項必須是 MySource 源而且類型為錯誤或警告的日志。你應(yīng)該使用下面那個代碼段?
A. EventLog myLog = new EventLog("Application", ".");
foreach (EventLogEntry entry in myLog.Entries)
{
if (entry.Source == "MySource")
{
PersistToDB(entry);
}
}
B. EventLog myLog = new EventLog("Application", ".");
myLog.Source = "MySource";
foreach (EventLogEntry entry in myLog.Entries)
{
if (entry.EntryType == (EventLogEntryType.Error &
EventLogEntryType.Warning))
{
PersistToDB(entry);
}
}
C. EventLog myLog = new EventLog("Application", ".");
foreach (EventLogEntry entry in myLog.Entries)
{
if (entry.Source == "MySource")
{
if (entry.EntryType == EventLogEntryType.Error ||entry.EntryType ==
EventLogEntryType.Warning)
{
PersistToDB(entry);
}
}
}
D. EventLog myLog = new EventLog("Application", ".");
myLog.Source = "MySource";
foreach (EventLogEntry entry in myLog.Entries)
{
if (entry.EntryType == EventLogEntryType.Error ||
entry.EntryType == EventLogEntryType.Warning)
{
PersistToDB(entry);
}
答案: C