第 1 題
你正在開發(fā)一個(gè)自定義事件處理去自動(dòng)打印所有打開的文檔。事件處理可以指定要打印的份
數(shù)。為此,你需要開發(fā)一個(gè)傳遞給事件處理程序的自定義事件參數(shù)類,你應(yīng)該使用下面那個(gè)
代碼段?
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)建一個(gè)使用非托管資源的類。這個(gè)類引用了使用托管資源的對(duì)象。你需要確保使用
這個(gè)類的用戶在不需要類實(shí)例的時(shí)候能夠夠釋放資源。你應(yīng)該做那三個(gè)工作?
(每個(gè)答案是解決方案的一部分)
A. 定義一個(gè)從WeakReference 繼承的類。
B. 定義一個(gè)實(shí)現(xiàn)IDisposable 接口的類。
C. 創(chuàng)建一個(gè)類析構(gòu)函數(shù),調(diào)用其它對(duì)象的方法去釋放托管資源。
D. 創(chuàng)建一個(gè)類析構(gòu)函數(shù),釋放非托管資源
E. 創(chuàng)建一個(gè)Dispose方法,調(diào)用System.GC.Collect 強(qiáng)制垃圾回收。
F. 創(chuàng)建一個(gè)Dispose方法,釋放非托管資源并且調(diào)用其它對(duì)象的方法釋放托管資源。
答案: B, D, F
第4 題
你正對(duì)一個(gè)應(yīng)用進(jìn)行調(diào)試。你需要找到引起異常的代碼行。請(qǐng)問,Exception 類的哪個(gè)屬性
能達(dá)到這個(gè)目的?
A. Data
B. Message
C. StackTrace
D. Source
答案: C
第 5 題
你正在測(cè)試一個(gè)新開發(fā)的方法 PersistToDB。這個(gè)方法接收一個(gè)類型為 EventLogEntry 的參數(shù),
方法沒有返回值。你需要?jiǎng)?chuàng)建一段代碼來幫助你測(cè)試這個(gè)方法。這段代碼必須從本地計(jì)算機(jī)的應(yīng)
用日志讀取日志項(xiàng)然后傳遞日志項(xiàng)給 PersistToDB 方法。要求,傳遞到 PersistToDB 方法的日
志項(xiàng)必須是 MySource 源而且類型為錯(cuò)誤或警告的日志。你應(yīng)該使用下面那個(gè)代碼段?
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