You are writing a method to compress an array of bytes. The bytes to be compressed are passed
to the method in a parameter named document.
You need to compress the contents of the incoming parameter.
Which code segment should you use?
A. Dim inStream As New MemoryStream(document)Dim zipStream As New
GZipStream( _inStream, CompressionMode.Compress)Dim result(document.Length) As
BytezipStream.Write(result, 0, result.Length)Return result
B. Dim objStream As New MemoryStream(document)Dim zipStream As New
GZipStream( _
objStream, CompressionMode.Compress)zipStream.Write(document, 0,
document.Length)zipStream.Close()Return objStream.ToArray
C. Dim outStream As New MemoryStreamDim zipStream As New GZipStream(
_outStream, CompressionMode.Compress)zipStream.Write(document, 0,
document.Length)zipStream.Close()Return outStream.ToArray
D. Dim objStream As New MemoryStream(document)Dim zipStream As New
GZipStream( _objStream, CompressionMode.Compress)Dim outStream As New
MemoryStreamDim b As IntegerWhile (b =
zipStream.ReadByte)outStream.WriteByte(CByte(b))End WhileReturn
outStream.ToArray
Answer: C
You need to read the entire contents of a file named Message.txt into a single string variable. Which code segment should you use?
You need to read the entire contents of a file named Message.txt into a single string variable.
Which code segment should you use?
A. String^ result = nullptr;StreamReader^ reader = gcnew
StreamReader(“Message.txt”);result = reader->Read().ToString();
B. String^ result = nullptr;StreamReader^ reader = gcnew
StreamReader(“Message.txt”);result = reader->ReadToEnd();
C. String^ result =String::Empty;StreamReader^ reader = gcnew
StreamReader(“Message.txt”); while (!reader->EndOfStream) {
result += reader->ToString();}
D. String^ result = nullptr;StreamReader^ reader = gcnew StreamReader(“Message.txt”); result =
reader->ReadLine();
Answer: B
Which code segment should you use?
A. String^ result = nullptr;StreamReader^ reader = gcnew
StreamReader(“Message.txt”);result = reader->Read().ToString();
B. String^ result = nullptr;StreamReader^ reader = gcnew
StreamReader(“Message.txt”);result = reader->ReadToEnd();
C. String^ result =String::Empty;StreamReader^ reader = gcnew
StreamReader(“Message.txt”); while (!reader->EndOfStream) {
result += reader->ToString();}
D. String^ result = nullptr;StreamReader^ reader = gcnew StreamReader(“Message.txt”); result =
reader->ReadLine();
Answer: B
You need to return the contents of an isolated storage file as a string. The file is machine-scoped and is named Settings.dat. Which code segment should you use?
You need to return the contents of an isolated storage file as a string. The file is machine-scoped
and is named Settings.dat. Which code segment should you use?
A. IsolatedStorageFileStream isoStream;isoStream = new IsolatedStorageFileStream(
“Settings.dat”, FileMode.Open); string result = new StreamReader(isoStream).ReadToEnd();
B. IsolatedStorageFile isoFile;isoFile = IsolatedStorageFile.GetMachineStoreForAssembly();
IsolatedStorageFileStream isoStream;isoStream = new IsolatedStorageFileStream(
“Settings.dat”, FileMode.Open, isoFile); string result = new
StreamReader(isoStream).ReadToEnd();
C. IsolatedStorageFileStream isoStream;isoStream = new IsolatedStorageFileStream(
“Settings.dat”, FileMode.Open); string result = isoStream.ToString();
D. IsolatedStorageFile isoFile;isoFile = IsolatedStorageFile.GetMachineStoreForAssembly();
IsolatedStorageFileStream isoStream;isoStream = new IsolatedStorageFileStream(
“Settings.dat”, FileMode.Open, isoFile); string result = isoStream.ToString();
A. IsolatedStorageFileStream isoStream;isoStream = new IsolatedStorageFileStream(
“Settings.dat”, FileMode.Open); string result = new StreamReader(isoStream).ReadToEnd();
B. IsolatedStorageFile isoFile;isoFile = IsolatedStorageFile.GetMachineStoreForAssembly();
IsolatedStorageFileStream isoStream;isoStream = new IsolatedStorageFileStream(
“Settings.dat”, FileMode.Open, isoFile); string result = new
StreamReader(isoStream).ReadToEnd();
C. IsolatedStorageFileStream isoStream;isoStream = new IsolatedStorageFileStream(
“Settings.dat”, FileMode.Open); string result = isoStream.ToString();
D. IsolatedStorageFile isoFile;isoFile = IsolatedStorageFile.GetMachineStoreForAssembly();
IsolatedStorageFileStream isoStream;isoStream = new IsolatedStorageFileStream(
“Settings.dat”, FileMode.Open, isoFile); string result = isoStream.ToString();
Answer: B
and is named Settings.dat. Which code segment should you use?
A. IsolatedStorageFileStream isoStream;isoStream = new IsolatedStorageFileStream(
“Settings.dat”, FileMode.Open); string result = new StreamReader(isoStream).ReadToEnd();
B. IsolatedStorageFile isoFile;isoFile = IsolatedStorageFile.GetMachineStoreForAssembly();
IsolatedStorageFileStream isoStream;isoStream = new IsolatedStorageFileStream(
“Settings.dat”, FileMode.Open, isoFile); string result = new
StreamReader(isoStream).ReadToEnd();
C. IsolatedStorageFileStream isoStream;isoStream = new IsolatedStorageFileStream(
“Settings.dat”, FileMode.Open); string result = isoStream.ToString();
D. IsolatedStorageFile isoFile;isoFile = IsolatedStorageFile.GetMachineStoreForAssembly();
IsolatedStorageFileStream isoStream;isoStream = new IsolatedStorageFileStream(
“Settings.dat”, FileMode.Open, isoFile); string result = isoStream.ToString();
A. IsolatedStorageFileStream isoStream;isoStream = new IsolatedStorageFileStream(
“Settings.dat”, FileMode.Open); string result = new StreamReader(isoStream).ReadToEnd();
B. IsolatedStorageFile isoFile;isoFile = IsolatedStorageFile.GetMachineStoreForAssembly();
IsolatedStorageFileStream isoStream;isoStream = new IsolatedStorageFileStream(
“Settings.dat”, FileMode.Open, isoFile); string result = new
StreamReader(isoStream).ReadToEnd();
C. IsolatedStorageFileStream isoStream;isoStream = new IsolatedStorageFileStream(
“Settings.dat”, FileMode.Open); string result = isoStream.ToString();
D. IsolatedStorageFile isoFile;isoFile = IsolatedStorageFile.GetMachineStoreForAssembly();
IsolatedStorageFileStream isoStream;isoStream = new IsolatedStorageFileStream(
“Settings.dat”, FileMode.Open, isoFile); string result = isoStream.ToString();
Answer: B
You need to create a class definition that is interoperable along with COM. You need to ensure that COM applications can create instances of the class and can call the GetAddress method. Which code segment should you use?
You need to create a class definition that is interoperable along with COM. You need to ensure
that COM applications can create instances of the class and can call the GetAddress method.
Which code segment should you use?
A. public ref class Customer {
string addressString;public:
Customer(string address) : addressString(address) { }
String^ GetAddress() { return addressString; }}
B. public ref class Customer {
static string addressString;public:
Customer() { }
static String^ GetAddress() { return addressString; }}
C. public ref class Customer {
string addressString;
public: Customer() { }
String^ GetAddress() { return addressString; }}
D. public ref class Customer {
string addressString;public:
Customer() { }private:
String^ GetAddress() { return addressString; }}
Answer: C
that COM applications can create instances of the class and can call the GetAddress method.
Which code segment should you use?
A. public ref class Customer {
string addressString;public:
Customer(string address) : addressString(address) { }
String^ GetAddress() { return addressString; }}
B. public ref class Customer {
static string addressString;public:
Customer() { }
static String^ GetAddress() { return addressString; }}
C. public ref class Customer {
string addressString;
public: Customer() { }
String^ GetAddress() { return addressString; }}
D. public ref class Customer {
string addressString;public:
Customer() { }private:
String^ GetAddress() { return addressString; }}
Answer: C
You are developing a method to decrypt data that was encrypted with the Triple DES Algorithm. The method accepts the following parameters:
You are developing a method to decrypt data that was encrypted with the Triple DES Algorithm.
The method accepts the following parameters: The byte array to be decrypted, which is named
cipherMessageThe key, which is named key An initialization vector, which is named iv You need
to decrypt the message by using the TripleDES class and place the result in a string.
Which code segment should you use?
A. TripleDES des = new TripleDESCryptoServiceProvider();des.BlockSize =
cipherMessage.Length;ICryptoTransform crypto = des.CreateDecryptor(key,
iv);MemoryStream cipherStream = new MemoryStream(cipherMessage);CryptoStream
cryptoStream =
new CryptoStream(
cipherStream, crypto, CryptoStreamMode.Read); string message;message = new
StreamReader(cryptoStream).ReadToEnd();
B. TripleDES des = new TripleDESCryptoServiceProvider();des.FeedbackSize =
cipherMessage.Length;ICryptoTransform crypto = des.CreateDecryptor(key,
iv);MemoryStream cipherStream = new MemoryStream(cipherMessage);CryptoStream
cryptoStream =
new CryptoStream(
cipherStream, crypto, CryptoStreamMode.Read); string message;message = new
StreamReader(cryptoStream).ReadToEnd();
C. TripleDES des = new TripleDESCryptoServiceProvider();ICryptoTransform crypto =
des.CreateDecryptor();MemoryStream cipherStream = new
MemoryStream(cipherMessage);CryptoStream cryptoStream =
new CryptoStream(
cipherStream, crypto, CryptoStreamMode.Read); string message;message = new
StreamReader(cryptoStream).ReadToEnd();
D. TripleDES des = new TripleDESCryptoServiceProvider();ICryptoTransform crypto =
des.CreateDecryptor(key, iv);MemoryStream cipherStream = new
MemoryStream(cipherMessage);CryptoStream cryptoStream =
new CryptoStream(
cipherStream, crypto, CryptoStreamMode.Read); string message;message = new
StreamReader(cryptoStream).ReadToEnd();
Answer: D
The method accepts the following parameters: The byte array to be decrypted, which is named
cipherMessageThe key, which is named key An initialization vector, which is named iv You need
to decrypt the message by using the TripleDES class and place the result in a string.
Which code segment should you use?
A. TripleDES des = new TripleDESCryptoServiceProvider();des.BlockSize =
cipherMessage.Length;ICryptoTransform crypto = des.CreateDecryptor(key,
iv);MemoryStream cipherStream = new MemoryStream(cipherMessage);CryptoStream
cryptoStream =
new CryptoStream(
cipherStream, crypto, CryptoStreamMode.Read); string message;message = new
StreamReader(cryptoStream).ReadToEnd();
B. TripleDES des = new TripleDESCryptoServiceProvider();des.FeedbackSize =
cipherMessage.Length;ICryptoTransform crypto = des.CreateDecryptor(key,
iv);MemoryStream cipherStream = new MemoryStream(cipherMessage);CryptoStream
cryptoStream =
new CryptoStream(
cipherStream, crypto, CryptoStreamMode.Read); string message;message = new
StreamReader(cryptoStream).ReadToEnd();
C. TripleDES des = new TripleDESCryptoServiceProvider();ICryptoTransform crypto =
des.CreateDecryptor();MemoryStream cipherStream = new
MemoryStream(cipherMessage);CryptoStream cryptoStream =
new CryptoStream(
cipherStream, crypto, CryptoStreamMode.Read); string message;message = new
StreamReader(cryptoStream).ReadToEnd();
D. TripleDES des = new TripleDESCryptoServiceProvider();ICryptoTransform crypto =
des.CreateDecryptor(key, iv);MemoryStream cipherStream = new
MemoryStream(cipherMessage);CryptoStream cryptoStream =
new CryptoStream(
cipherStream, crypto, CryptoStreamMode.Read); string message;message = new
StreamReader(cryptoStream).ReadToEnd();
Answer: D
You are creating an application that lists processes on remote computers.
You are creating an application that lists processes on remote computers. The application
requires a method that performs the following tasks: Accept the remote computer name as a
string parameter named strComputer.Return an ArrayList object that contains the names of all
processes that are running on that computer. You need to write a code segment that retrieves the
name of each process that is running on the remote computer and adds the name to the ArrayList
object. Which code segment should you use?
A. ArrayList al = new ArrayList();Process[] procs =
Process.GetProcessesByName(strComputer);foreach (Process proc in procs) {
al.Add(proc);}
B. ArrayList al = new ArrayList();Process[] procs = Process.GetProcesses(strComputer);foreach
(Process proc in procs) {
al.Add(proc);}
C. ArrayList al = new ArrayList();Process[] procs =
Process.GetProcessesByName(strComputer);foreach (Process proc in procs) {
al.Add(proc.ProcessName);}
D. ArrayList al = new ArrayList();Process[] procs = Process.GetProcesses(strComputer);foreach
(Process proc in procs) {
al.Add(proc.ProcessName);}
Answer: D
requires a method that performs the following tasks: Accept the remote computer name as a
string parameter named strComputer.Return an ArrayList object that contains the names of all
processes that are running on that computer. You need to write a code segment that retrieves the
name of each process that is running on the remote computer and adds the name to the ArrayList
object. Which code segment should you use?
A. ArrayList al = new ArrayList();Process[] procs =
Process.GetProcessesByName(strComputer);foreach (Process proc in procs) {
al.Add(proc);}
B. ArrayList al = new ArrayList();Process[] procs = Process.GetProcesses(strComputer);foreach
(Process proc in procs) {
al.Add(proc);}
C. ArrayList al = new ArrayList();Process[] procs =
Process.GetProcessesByName(strComputer);foreach (Process proc in procs) {
al.Add(proc.ProcessName);}
D. ArrayList al = new ArrayList();Process[] procs = Process.GetProcesses(strComputer);foreach
(Process proc in procs) {
al.Add(proc.ProcessName);}
Answer: D
You are testing a newly developed method named PersistToDB. This method accepts a parameter of type EventLogEntry
You are testing a newly developed method named PersistToDB. This method accepts a
parameter of type EventLogEntry. This method does not return a value. You need to create a
code segment that helps you to test the method. The code segment must read entries from the
application log of local computers and then pass the entries on to the PersistToDB method. The
code block must pass only events of type Error or Warning from the source MySource to the
PersistToDB method. Which code segment should you use?
A. EventLog^ myLog = gcnew EventLog(“Application”, “.”);
for each (EventLogEntry^ entry in myLog->Entries) {
if (entry->Source == "MySource") {
PersistToDB(entry);
}}
B. EventLog^ myLog = gcnew EventLog(“Application”, “.”);
myLog->Source = “MySource”;
for each (EventLogEntry^ entry in myLog->Entries) {
if (entry->EntryType == (EventLogEntryType::Error &
EventLogEntryType::Warning)) {
PersistToDB(entry);}}
C. EventLog^ myLog = gcnew EventLog(“Application”, “.”);
for each (EventLogEntry^ entry in myLog->Entries) {
if (entry->Source == "MySource") {
if (entry->EntryType == EventLogEntryType::Error ||
entry->EntryType == EventLogEntryType::Warning) {
PersistToDB(entry);
}
}}
D. EventLog^ myLog = gcnew EventLog(“Application”, “.”);
myLog->Source = “MySource”;
for each (EventLogEntry^ entry in myLog->Entries) {
if (entry->EntryType == EventLogEntryType::Error ||
entry->EntryType == EventLogEntryType::Warning) {
PersistToDB(entry);
}}
Answer: C
parameter of type EventLogEntry. This method does not return a value. You need to create a
code segment that helps you to test the method. The code segment must read entries from the
application log of local computers and then pass the entries on to the PersistToDB method. The
code block must pass only events of type Error or Warning from the source MySource to the
PersistToDB method. Which code segment should you use?
A. EventLog^ myLog = gcnew EventLog(“Application”, “.”);
for each (EventLogEntry^ entry in myLog->Entries) {
if (entry->Source == "MySource") {
PersistToDB(entry);
}}
B. EventLog^ myLog = gcnew EventLog(“Application”, “.”);
myLog->Source = “MySource”;
for each (EventLogEntry^ entry in myLog->Entries) {
if (entry->EntryType == (EventLogEntryType::Error &
EventLogEntryType::Warning)) {
PersistToDB(entry);}}
C. EventLog^ myLog = gcnew EventLog(“Application”, “.”);
for each (EventLogEntry^ entry in myLog->Entries) {
if (entry->Source == "MySource") {
if (entry->EntryType == EventLogEntryType::Error ||
entry->EntryType == EventLogEntryType::Warning) {
PersistToDB(entry);
}
}}
D. EventLog^ myLog = gcnew EventLog(“Application”, “.”);
myLog->Source = “MySource”;
for each (EventLogEntry^ entry in myLog->Entries) {
if (entry->EntryType == EventLogEntryType::Error ||
entry->EntryType == EventLogEntryType::Warning) {
PersistToDB(entry);
}}
Answer: C
You are testing a newly developed method named PersistToDB. This method accepts a parameter of type EventLogEntry.
You are testing a newly developed method named PersistToDB. This method accepts a
parameter of type EventLogEntry. This method does not return a value. You need to create a
code segment that helps you to test the method. The code segment must read entries from the
application log of local computers and then pass the entries on to the PersistToDB method. The
code block must pass only events of type Error or Warning from the source MySource to the
PersistToDB method.
Which code segment should you use?
A. Dim myLog As New EventLog("Application", ".")
For Each entry As EventLogEntry In myLog.Entries
If entry.Source = "MySource" Then
PersistToDB(entry)
End If
Next
B. Dim myLog as New EventLog("Application", ".")
myLog.Source = "MySource"
For Each entry As EventLogEntry In myLog.Entries
If entry.EntryType = (EventLogEntryType.Error And _
EventLogEntryType.Warning) Then
PersistToDB(entry)
End If
Next
C. Dim myLog as New EventLog("Application", ".")
For Each entry As EventLogEntry In myLog.Entries
If entry.Source = "MySource" Then
If (entry.EntryType = EventLogEntryType.Error) Or _
(entry.EntryType = EventLogEntryType.Warning) Then
PersistToDB(entry)
End If
End If
Next
D. Dim myLog as New EventLog("Application", ".")
myLog.Source = "MySource"
For Each entry As EventLogEntry In myLog.Entries
If (entry.EntryType = EventLogEntryType.Error) Or _
(entry.EntryType = EventLogEntryType.Warning) Then
PersistToDB(entry)
End If
Next
Answer: C
parameter of type EventLogEntry. This method does not return a value. You need to create a
code segment that helps you to test the method. The code segment must read entries from the
application log of local computers and then pass the entries on to the PersistToDB method. The
code block must pass only events of type Error or Warning from the source MySource to the
PersistToDB method.
Which code segment should you use?
A. Dim myLog As New EventLog("Application", ".")
For Each entry As EventLogEntry In myLog.Entries
If entry.Source = "MySource" Then
PersistToDB(entry)
End If
Next
B. Dim myLog as New EventLog("Application", ".")
myLog.Source = "MySource"
For Each entry As EventLogEntry In myLog.Entries
If entry.EntryType = (EventLogEntryType.Error And _
EventLogEntryType.Warning) Then
PersistToDB(entry)
End If
Next
C. Dim myLog as New EventLog("Application", ".")
For Each entry As EventLogEntry In myLog.Entries
If entry.Source = "MySource" Then
If (entry.EntryType = EventLogEntryType.Error) Or _
(entry.EntryType = EventLogEntryType.Warning) Then
PersistToDB(entry)
End If
End If
Next
D. Dim myLog as New EventLog("Application", ".")
myLog.Source = "MySource"
For Each entry As EventLogEntry In myLog.Entries
If (entry.EntryType = EventLogEntryType.Error) Or _
(entry.EntryType = EventLogEntryType.Warning) Then
PersistToDB(entry)
End If
Next
Answer: C
You are creating an assembly named Braindumps1. Braindumps1 contains a public method. The global cache contains a second assembly named Braindumps2. You must ensure that the public method is only called from Braindumps2. Which permission class should you use?
You are creating an assembly named Braindumps1. Braindumps1 contains a public method.
The global cache contains a second assembly named Braindumps2.
You must ensure that the public method is only called from Braindumps2.
Which permission class should you use?
A. GacIdentityPermission
B. PublisherIdentityPermission
C. DataProtectionPermission
D. StrongNameIdentityPermission
Answer: A
The global cache contains a second assembly named Braindumps2.
You must ensure that the public method is only called from Braindumps2.
Which permission class should you use?
A. GacIdentityPermission
B. PublisherIdentityPermission
C. DataProtectionPermission
D. StrongNameIdentityPermission
Answer: A
You create a class library that contains the class hierarchy defined in the following code segment.
You create a class library that contains the class hierarchy defined in the following code segment.
(Line numbers are included for reference only.)
01 public class Group {
02 public Employee[] Employees;
03 }
04 public class Employee {
05 public string Name;
06 }
07 public class Manager : Employee {
08 public int Level;
09 }
You create an instance of the Group class. You populate the fields of the instance. When you
attempt to serialize the instance by using the Serialize method of the XmlSerializer class, you
receive InvalidOperationException. You also receive the following error message: "There was an
error generating the XML document."
You need to modify the code segment so that you can successfully serialize instances of the
Group class by using the XmlSerializer class. You also need to ensure that the XML output
contains an element for all public fields in the class hierarchy. What should you do?
A. Insert the following code between lines 1 and 2 of the code segment:
[XmlArrayItem(Type = typeof(Employee))]
[XmlArrayItem(Type = typeof(Manager))]
B. Insert the following code between lines 1 and 2 of the code segment:
[XmlElement(Type = typeof(Employees))]
C. Insert the following code between lines 1 and 2 of the code segment:
[XmlArray(ElementName="Employees")]
D. Insert the following code between lines 3 and 4 of the code segment:
[XmlElement(Type = typeof(Employee))]
andInsert the following code between lines 6 and 7 of the code segment:
[XmlElement(Type = typeof(Manager))]
Answer: A
(Line numbers are included for reference only.)
01 public class Group {
02 public Employee[] Employees;
03 }
04 public class Employee {
05 public string Name;
06 }
07 public class Manager : Employee {
08 public int Level;
09 }
You create an instance of the Group class. You populate the fields of the instance. When you
attempt to serialize the instance by using the Serialize method of the XmlSerializer class, you
receive InvalidOperationException. You also receive the following error message: "There was an
error generating the XML document."
You need to modify the code segment so that you can successfully serialize instances of the
Group class by using the XmlSerializer class. You also need to ensure that the XML output
contains an element for all public fields in the class hierarchy. What should you do?
A. Insert the following code between lines 1 and 2 of the code segment:
[XmlArrayItem(Type = typeof(Employee))]
[XmlArrayItem(Type = typeof(Manager))]
B. Insert the following code between lines 1 and 2 of the code segment:
[XmlElement(Type = typeof(Employees))]
C. Insert the following code between lines 1 and 2 of the code segment:
[XmlArray(ElementName="Employees")]
D. Insert the following code between lines 3 and 4 of the code segment:
[XmlElement(Type = typeof(Employee))]
andInsert the following code between lines 6 and 7 of the code segment:
[XmlElement(Type = typeof(Manager))]
Answer: A
You write the following code to implement the BraindumpsClass.MyMethod function. public class BraindumpsClass { public int MyMethod(int arg) { return arg; }} You need to call the BraindumpsClass.MyMethod function dynamically from an unrelated class in your assembly. Which code segment should you use?
You write the following code to implement the BraindumpsClass.MyMethod function.
public class BraindumpsClass {
public int MyMethod(int arg) {
return arg;
}}
You need to call the BraindumpsClass.MyMethod function dynamically from an unrelated class in
your assembly. Which code segment should you use?
A. BraindumpsClass myClass = new BraindumpsClass();
Type t = typeof(BraindumpsClass);
MethodInfo m = t.GetMethod(“MyMethod”);
int i = (int)m.Invoke(this, new object[] { 1 });
B. BraindumpsClass myClass = new BraindumpsClass();
Type t = typeof(BraindumpsClass);
MethodInfo m = t.GetMethod(“MyMethod”);
int i = (int) m.Invoke(myClass, new object[] { 1 });
C. BraindumpsClass myClass = new BraindumpsClass();
Type t = typeof(BraindumpsClass);
MethodInfo m = t.GetMethod(“BraindumpsClass.MyMethod”);
int i = (int)m.Invoke(myClass, new object[] { 1 });
D. Type t = Type.GetType(“BraindumpsClass”);
MethodInfo m = t.GetMethod(“MyMethod”);
int i = (int)m.Invoke(this, new object[] { 1 });
Answer: B
public class BraindumpsClass {
public int MyMethod(int arg) {
return arg;
}}
You need to call the BraindumpsClass.MyMethod function dynamically from an unrelated class in
your assembly. Which code segment should you use?
A. BraindumpsClass myClass = new BraindumpsClass();
Type t = typeof(BraindumpsClass);
MethodInfo m = t.GetMethod(“MyMethod”);
int i = (int)m.Invoke(this, new object[] { 1 });
B. BraindumpsClass myClass = new BraindumpsClass();
Type t = typeof(BraindumpsClass);
MethodInfo m = t.GetMethod(“MyMethod”);
int i = (int) m.Invoke(myClass, new object[] { 1 });
C. BraindumpsClass myClass = new BraindumpsClass();
Type t = typeof(BraindumpsClass);
MethodInfo m = t.GetMethod(“BraindumpsClass.MyMethod”);
int i = (int)m.Invoke(myClass, new object[] { 1 });
D. Type t = Type.GetType(“BraindumpsClass”);
MethodInfo m = t.GetMethod(“MyMethod”);
int i = (int)m.Invoke(this, new object[] { 1 });
Answer: B
You need to select a class that is optimized for key-based item retrieval from both small and large collections. Which class should you choose?
You need to select a class that is optimized for key-based item retrieval from both small and large
collections. Which class should you choose?
A. OrderedDictionary class
B. HybridDictionary class
C. ListDictionary class
D. Hashtable class
Answer: B
collections. Which class should you choose?
A. OrderedDictionary class
B. HybridDictionary class
C. ListDictionary class
D. Hashtable class
Answer: B
You are developing an application to assist the user in conducting electronic surveys. The survey consists of 25 true-or-false questions. You need to perform the following tasks: Initialize each answer to true.Minimize the amount of memory used by each survey. Which storage option should you choose?
You are developing an application to assist the user in conducting electronic surveys. The survey
consists of 25 true-or-false questions. You need to perform the following tasks:
Initialize each answer to true.Minimize the amount of memory used by each survey.
Which storage option should you choose?
A. Dim answers As New BitVector32(1)
B. Dim answers As New BitVector32(-1)
C. Dim answers As New BitArray(1)
D. Dim answers As New BitArray(-1)
Answer: B
consists of 25 true-or-false questions. You need to perform the following tasks:
Initialize each answer to true.Minimize the amount of memory used by each survey.
Which storage option should you choose?
A. Dim answers As New BitVector32(1)
B. Dim answers As New BitVector32(-1)
C. Dim answers As New BitArray(1)
D. Dim answers As New BitArray(-1)
Answer: B
You are developing a class library. Portions of your code need to access system environment variables. You need to force a runtime SecurityException only when callers that are higher in the call stack do not have the necessary permissions. Which call method should you use?
You are developing a class library. Portions of your code need to access system environment
variables.
You need to force a runtime SecurityException only when callers that are higher in the call stack
do not have the necessary permissions.
Which call method should you use?
A. Demand()
B. Assert()
C. PermitOnly()
D. Deny()
Answer: A
variables.
You need to force a runtime SecurityException only when callers that are higher in the call stack
do not have the necessary permissions.
Which call method should you use?
A. Demand()
B. Assert()
C. PermitOnly()
D. Deny()
Answer: A
You need to write a code segment that transfers the first 80 bytes from a stream variable named stream1 into a new byte array named byteArray. You also need to ensure that the code segment assigns the number of bytes that are transferred to an integer variable named bytesTransferred. Which code segment should you use?
You need to write a code segment that transfers the first 80 bytes from a stream variable named
stream1 into a new byte array named byteArray. You also need to ensure that the code segment
assigns the number of bytes that are transferred to an integer variable named bytesTransferred.
Which code segment should you use?
A. bytesTransferred = stream1.Read(byteArray, 0, 80)
B. For i As Integer = 1 To 80
stream1.WriteByte(byteArray(i))
bytesTransferred = i
If Not stream1.CanWrite Then
Exit For
End IfNext
C. While bytesTransferred < 80
stream1.Seek(1, SeekOrigin.Current)
byteArray(bytesTransferred) = _
Convert.ToByte(stream1.ReadByte())bytesTransferred += 1End While
D. stream1.Write(byteArray, 0, 80)bytesTransferred = byteArray.Length
Answer: A
stream1 into a new byte array named byteArray. You also need to ensure that the code segment
assigns the number of bytes that are transferred to an integer variable named bytesTransferred.
Which code segment should you use?
A. bytesTransferred = stream1.Read(byteArray, 0, 80)
B. For i As Integer = 1 To 80
stream1.WriteByte(byteArray(i))
bytesTransferred = i
If Not stream1.CanWrite Then
Exit For
End IfNext
C. While bytesTransferred < 80
stream1.Seek(1, SeekOrigin.Current)
byteArray(bytesTransferred) = _
Convert.ToByte(stream1.ReadByte())bytesTransferred += 1End While
D. stream1.Write(byteArray, 0, 80)bytesTransferred = byteArray.Length
Answer: A
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?
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.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;
}
}
}
Answer: C
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.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;
}
}
}
Answer: C
You are loading a new assembly into an application. You need to override the default evidence for the assembly. You require the common language runtime (CLR) to grant the assembly a permission set, as if the assembly were loaded from the local intranet zone. You need to build the evidence collection. Which code segment should you use?
You are loading a new assembly into an application. You need to override the default evidence
for the assembly. You require the common language runtime (CLR) to grant the assembly a
permission set, as if the assembly were loaded from the local intranet zone.
You need to build the evidence collection. Which code segment should you use?
A. Evidence^ evidence = gcnew
Evidence(Assembly::GetExecutingAssembly()->Evidence);
B. Evidence^ evidence = gcnew Evidence();evidence->AddAssembly(gcnew
Zone(SecurityZone::Intranet));
C. Evidence^ evidence = gcnew Evidence();evidence->AddHost(gcnew
Zone(SecurityZone::Intranet));
D. Evidence^ evidence = gcnew Evidence(AppDomain::CurrentDomain->Evidence);
Answer: C
for the assembly. You require the common language runtime (CLR) to grant the assembly a
permission set, as if the assembly were loaded from the local intranet zone.
You need to build the evidence collection. Which code segment should you use?
A. Evidence^ evidence = gcnew
Evidence(Assembly::GetExecutingAssembly()->Evidence);
B. Evidence^ evidence = gcnew Evidence();evidence->AddAssembly(gcnew
Zone(SecurityZone::Intranet));
C. Evidence^ evidence = gcnew Evidence();evidence->AddHost(gcnew
Zone(SecurityZone::Intranet));
D. Evidence^ evidence = gcnew Evidence(AppDomain::CurrentDomain->Evidence);
Answer: C
You develop a service application named FileService.
You develop a service application named FileService. You deploy the service application to
multiple servers on your network. You implement the following code segment. (Line numbers are
included for reference only.)
01 public :
02 void StartService(String^ serverName){
03
04 ServiceController^ crtl = gcnew
05 ServiceController(“FileService”);
06 if (crtl->Status == ServiceControllerStatus::Stopped){}
07 }
You need to develop a routine that will start FileService if it stops. The routine must start
FileService on the server identified by the serverName input parameter.
Which two lines of code should you add to the code segment? (Each correct answer presents
part of the solution. Choose two.)
A. Insert the following line of code between lines 03 and 04:crtl.ServiceName = serverName;
B. Insert the following line of code between lines 03 and 04:crtl.MachineName = serverName;
C. Insert the following line of code between lines 03 and 04:crtl.Site.Name = serverName;
D. Insert the following line of code between lines 04 and 05:crtl.Continue();
E. Insert the following line of code between lines 04 and 05:crtl.Start();
F. Insert the following line of code between lines 04 and 05:crtl.ExecuteCommand(0);
Answer: B, E
multiple servers on your network. You implement the following code segment. (Line numbers are
included for reference only.)
01 public :
02 void StartService(String^ serverName){
03
04 ServiceController^ crtl = gcnew
05 ServiceController(“FileService”);
06 if (crtl->Status == ServiceControllerStatus::Stopped){}
07 }
You need to develop a routine that will start FileService if it stops. The routine must start
FileService on the server identified by the serverName input parameter.
Which two lines of code should you add to the code segment? (Each correct answer presents
part of the solution. Choose two.)
A. Insert the following line of code between lines 03 and 04:crtl.ServiceName = serverName;
B. Insert the following line of code between lines 03 and 04:crtl.MachineName = serverName;
C. Insert the following line of code between lines 03 and 04:crtl.Site.Name = serverName;
D. Insert the following line of code between lines 04 and 05:crtl.Continue();
E. Insert the following line of code between lines 04 and 05:crtl.Start();
F. Insert the following line of code between lines 04 and 05:crtl.ExecuteCommand(0);
Answer: B, E
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?
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. public ref class MYDictionary : public Dictionary<String^, String^>{};
B. public ref class MYDictionary : public Hashtable{};
C. public ref class MYDictionary : public IDictionary{};
D. public ref class MYDictionary {};Distionary<String^, String^>t = gcnew Dictionary<String^,
String^>();MyDictionary dictionary = (MyDictionary)t;
Answer: A
MyDictionary. You need to ensure that the dictionary is type safe.
Which code segment should you use?
A. public ref class MYDictionary : public Dictionary<String^, String^>{};
B. public ref class MYDictionary : public Hashtable{};
C. public ref class MYDictionary : public IDictionary{};
D. public ref class MYDictionary {};Distionary<String^, String^>t = gcnew Dictionary<String^,
String^>();MyDictionary dictionary = (MyDictionary)t;
Answer: A
You are defining a class named BraindumpsClass that contains several child objects.
You are defining a class named BraindumpsClass that contains several child objects.
BraindumpsClass contains a method named ProcessChildren that performs actions on the child
objects. BraindumpsClass objects will be serializable.
You need to ensure that the ProcessChildren method is executed after the BraindumpsClass
object and all its child objects are reconstructed.
Which two actions should you perform? (Each correct answer presents part of the solution.
Choose two.)
A. Apply the OnDeserializing attribute to the ProcessChildren method.
B. Specify that BraindumpsClass implements the IDeserializationCallback interface.
C. Specify that BraindumpsClass inherits from the ObjectManager class.
D. Apply the OnSerialized attribute to the ProcessChildren method.
E. Create a GetObjectData method that calls ProcessChildren.
F. Create an OnDeserialization method that calls ProcessChildren.
Answer: B, F
BraindumpsClass contains a method named ProcessChildren that performs actions on the child
objects. BraindumpsClass objects will be serializable.
You need to ensure that the ProcessChildren method is executed after the BraindumpsClass
object and all its child objects are reconstructed.
Which two actions should you perform? (Each correct answer presents part of the solution.
Choose two.)
A. Apply the OnDeserializing attribute to the ProcessChildren method.
B. Specify that BraindumpsClass implements the IDeserializationCallback interface.
C. Specify that BraindumpsClass inherits from the ObjectManager class.
D. Apply the OnSerialized attribute to the ProcessChildren method.
E. Create a GetObjectData method that calls ProcessChildren.
F. Create an OnDeserialization method that calls ProcessChildren.
Answer: B, F
You need to read the entire contents of a file named Message.txt into a single string variable. Which code segment should you use?
You need to read the entire contents of a file named Message.txt into a single string variable.
Which code segment should you use?
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();
Answer: B
Which code segment should you use?
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();
Answer: B
You are writing a method to compress an array of bytes.
You are writing a method to compress an array of bytes. The array is passed to the method in a
parameter named document. You need to compress the incoming array of bytes and return the
result as an array of bytes. Which code segment should you use?
A. MemoryStream^ strm = gcnew MemoryStream(document);
DeflateStream^ deflate = gcnew DeflateStream(strm,
CompressionMode::Compress);
array<Byte>^ result = gcnew array<Byte>(document->Length);
deflate->Write(result, 0, result->Length);
return result;
B. MemoryStream^ strm = gcnew MemoryStream(document);
DeflateStream^ deflate = gcnew DeflateStream(strm,
CompressionMode::Compress);
deflate->Write(document, 0, document->Length);
deflate->Close();return strm->ToArray();
C. MemoryStream^ strm = gcnew MemoryStream();
DeflateStream^ deflate = gcnew
DeflateStream(strm,CompressionMode::Compress);deflate->Write(document, 0, document-
>Length);
deflate->Close();
return strm->ToArray();
D. MemoryStream^ inStream = gcnew MemoryStream(document);DeflateStream^
deflate = gcnew DeflateStream(inStream,
CompressionMode::Compress);
MemoryStream^ outStream = gcnew MemoryStream()
;int b;
while ((b = deflate->ReadByte()) != -1) {
outStream->WriteByte((Byte)b);
}
return outStream->ToArray();
Answer: C
parameter named document. You need to compress the incoming array of bytes and return the
result as an array of bytes. Which code segment should you use?
A. MemoryStream^ strm = gcnew MemoryStream(document);
DeflateStream^ deflate = gcnew DeflateStream(strm,
CompressionMode::Compress);
array<Byte>^ result = gcnew array<Byte>(document->Length);
deflate->Write(result, 0, result->Length);
return result;
B. MemoryStream^ strm = gcnew MemoryStream(document);
DeflateStream^ deflate = gcnew DeflateStream(strm,
CompressionMode::Compress);
deflate->Write(document, 0, document->Length);
deflate->Close();return strm->ToArray();
C. MemoryStream^ strm = gcnew MemoryStream();
DeflateStream^ deflate = gcnew
DeflateStream(strm,CompressionMode::Compress);deflate->Write(document, 0, document-
>Length);
deflate->Close();
return strm->ToArray();
D. MemoryStream^ inStream = gcnew MemoryStream(document);DeflateStream^
deflate = gcnew DeflateStream(inStream,
CompressionMode::Compress);
MemoryStream^ outStream = gcnew MemoryStream()
;int b;
while ((b = deflate->ReadByte()) != -1) {
outStream->WriteByte((Byte)b);
}
return outStream->ToArray();
Answer: C
You are developing an application to assist the user in conducting electronic surveys.
You are developing an application to assist the user in conducting electronic surveys. The survey
consists of 25 true-or-false questions. You need to perform the following tasks:
Initialize each answer to true.Minimize the amount of memory used by each survey.
Which storage option should you choose?
A. BitVector32 answers = new BitVector32(1);
B. BitVector32 answers = new BitVector32(-1);
C. BitArray answers = new BitArray(1);
D. BitArray answers = new BitArray(-1);
Answer: B
consists of 25 true-or-false questions. You need to perform the following tasks:
Initialize each answer to true.Minimize the amount of memory used by each survey.
Which storage option should you choose?
A. BitVector32 answers = new BitVector32(1);
B. BitVector32 answers = new BitVector32(-1);
C. BitArray answers = new BitArray(1);
D. BitArray answers = new BitArray(-1);
Answer: B
You create an application that stores information about your customers who reside in various regions
You create an application that stores information about your customers who reside in various
regions. You are developing internal utilities for this application.
You need to gather regional information about your customers in Canada.
Which code segment should you use?
A. foreach (CultureInfo culture in
CultureInfo.GetCultures(CultureTypes.SpecificCultures)) { // Output the region
information...}
B. CultureInfo cultureInfo = new CultureInfo(“CA”); // Output the region information...
C. RegionInfo regionInfo = new RegionInfo(“CA”); // Output the region information…
D. RegionInfo regionInfo = new RegionInfo(“”);if(regionInfo.Name == “CA”) {
// Output the region information...}
Answer: C
regions. You are developing internal utilities for this application.
You need to gather regional information about your customers in Canada.
Which code segment should you use?
A. foreach (CultureInfo culture in
CultureInfo.GetCultures(CultureTypes.SpecificCultures)) { // Output the region
information...}
B. CultureInfo cultureInfo = new CultureInfo(“CA”); // Output the region information...
C. RegionInfo regionInfo = new RegionInfo(“CA”); // Output the region information…
D. RegionInfo regionInfo = new RegionInfo(“”);if(regionInfo.Name == “CA”) {
// Output the region information...}
Answer: C
You are using the Microsoft Visual Studio 2005 IDE to examine the output of a method that returns a string.
You are using the Microsoft Visual Studio 2005 IDE to examine the output of a method that
returns a string. You assign the output of the method to a string variable named fName. You need
to write a code segment that prints the following on a single line The message: "Test Failed: " The
value of fName if the value of fName does not equal "Braindumps" You also need to ensure that
the code segment simultaneously facilitates uninterrupted execution of the application. Which
code segment should you use?
A. Debug.Assert(fName == “Braindumps”, “Test Failed: ”, fName);
B. Debug.WriteLineIf(fName != “Braindumps”, fName, “Test Failed”);
C. if (fName != "Braindumps") {
Debug.Print(“Test Failed: ”);
Debug.Print(fName);
}
D. if (fName != "Braindumps") {
Debug.WriteLine(“Test Failed: ”);
Debug.WriteLine (fName);
}
Answer: B
returns a string. You assign the output of the method to a string variable named fName. You need
to write a code segment that prints the following on a single line The message: "Test Failed: " The
value of fName if the value of fName does not equal "Braindumps" You also need to ensure that
the code segment simultaneously facilitates uninterrupted execution of the application. Which
code segment should you use?
A. Debug.Assert(fName == “Braindumps”, “Test Failed: ”, fName);
B. Debug.WriteLineIf(fName != “Braindumps”, fName, “Test Failed”);
C. if (fName != "Braindumps") {
Debug.Print(“Test Failed: ”);
Debug.Print(fName);
}
D. if (fName != "Braindumps") {
Debug.WriteLine(“Test Failed: ”);
Debug.WriteLine (fName);
}
Answer: B
You are writing a method that returns an ArrayList named al. You need to ensure that changes to the ArrayList are performed in a thread-safe manner. Which code segment should you use?
You are writing a method that returns an ArrayList named al. You need to ensure that changes to
the ArrayList are performed in a thread-safe manner. Which code segment should you use?
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;
Answer: D
the ArrayList are performed in a thread-safe manner. Which code segment should you use?
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;
Answer: D
You need to select a class that is optimized for key-based item retrieval from both small and large collections. Which class should you choose?
You need to select a class that is optimized for key-based item retrieval from both small and large
collections. Which class should you choose?
A. OrderedDictionary class
B. HybridDictionary class
C. ListDictionary class
D. Hashtable class
Answer: B
collections. Which class should you choose?
A. OrderedDictionary class
B. HybridDictionary class
C. ListDictionary class
D. Hashtable class
Answer: B
You are developing an application to assist the user in conducting electronic surveys
You are developing an application to assist the user in conducting electronic surveys. The survey
consists of 25 true-or-false questions. You need to perform the following tasks:
Initialize each answer to true.Minimize the amount of memory used by each survey.
Which storage option should you choose?
A. Dim answers As New BitVector32(1)
B. Dim answers As New BitVector32(-1)
C. Dim answers As New BitArray(1)
D. Dim answers As New BitArray(-1)
Answer: B
consists of 25 true-or-false questions. You need to perform the following tasks:
Initialize each answer to true.Minimize the amount of memory used by each survey.
Which storage option should you choose?
A. Dim answers As New BitVector32(1)
B. Dim answers As New BitVector32(-1)
C. Dim answers As New BitArray(1)
D. Dim answers As New BitArray(-1)
Answer: B
You are developing a class library. Portions of your code need to access system environment variables.
You are developing a class library. Portions of your code need to access system environment
variables.
You need to force a runtime SecurityException only when callers that are higher in the call stack
do not have the necessary permissions.
Which call method should you use?
A. Demand()
B. Assert()
C. PermitOnly()
D. Deny()
Answer: A
variables.
You need to force a runtime SecurityException only when callers that are higher in the call stack
do not have the necessary permissions.
Which call method should you use?
A. Demand()
B. Assert()
C. PermitOnly()
D. Deny()
Answer: A
You need to write a code segment that transfers the first 80 bytes from a stream variable named stream1 into a new byte array named byteArray.
You need to write a code segment that transfers the first 80 bytes from a stream variable named
stream1 into a new byte array named byteArray. You also need to ensure that the code segment
assigns the number of bytes that are transferred to an integer variable named bytesTransferred.
Which code segment should you use?
A. bytesTransferred = stream1.Read(byteArray, 0, 80)
B. For i As Integer = 1 To 80
stream1.WriteByte(byteArray(i))
bytesTransferred = i
If Not stream1.CanWrite Then
Exit For
End IfNext
C. While bytesTransferred < 80
stream1.Seek(1, SeekOrigin.Current)
byteArray(bytesTransferred) = _
Convert.ToByte(stream1.ReadByte())bytesTransferred += 1End While
D. stream1.Write(byteArray, 0, 80)bytesTransferred = byteArray.Length
Answer: A
stream1 into a new byte array named byteArray. You also need to ensure that the code segment
assigns the number of bytes that are transferred to an integer variable named bytesTransferred.
Which code segment should you use?
A. bytesTransferred = stream1.Read(byteArray, 0, 80)
B. For i As Integer = 1 To 80
stream1.WriteByte(byteArray(i))
bytesTransferred = i
If Not stream1.CanWrite Then
Exit For
End IfNext
C. While bytesTransferred < 80
stream1.Seek(1, SeekOrigin.Current)
byteArray(bytesTransferred) = _
Convert.ToByte(stream1.ReadByte())bytesTransferred += 1End While
D. stream1.Write(byteArray, 0, 80)bytesTransferred = byteArray.Length
Answer: A
You are creating a class named Age.
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.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;
}
}
}
Answer: C
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.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;
}
}
}
Answer: C
You are loading a new assembly into an application. You need to override the default evidence for the assembly.
You are loading a new assembly into an application. You need to override the default evidence
for the assembly. You require the common language runtime (CLR) to grant the assembly a
permission set, as if the assembly were loaded from the local intranet zone.
You need to build the evidence collection. Which code segment should you use?
A. Evidence^ evidence = gcnew
Evidence(Assembly::GetExecutingAssembly()->Evidence);
B. Evidence^ evidence = gcnew Evidence();evidence->AddAssembly(gcnew
Zone(SecurityZone::Intranet));
C. Evidence^ evidence = gcnew Evidence();evidence->AddHost(gcnew
Zone(SecurityZone::Intranet));
D. Evidence^ evidence = gcnew Evidence(AppDomain::CurrentDomain->Evidence);
Answer: C
for the assembly. You require the common language runtime (CLR) to grant the assembly a
permission set, as if the assembly were loaded from the local intranet zone.
You need to build the evidence collection. Which code segment should you use?
A. Evidence^ evidence = gcnew
Evidence(Assembly::GetExecutingAssembly()->Evidence);
B. Evidence^ evidence = gcnew Evidence();evidence->AddAssembly(gcnew
Zone(SecurityZone::Intranet));
C. Evidence^ evidence = gcnew Evidence();evidence->AddHost(gcnew
Zone(SecurityZone::Intranet));
D. Evidence^ evidence = gcnew Evidence(AppDomain::CurrentDomain->Evidence);
Answer: C
You develop a service application named FileService. You deploy the service application to multiple servers on your network.
You develop a service application named FileService. You deploy the service application to
multiple servers on your network. You implement the following code segment. (Line numbers are
included for reference only.)
01 public :
02 void StartService(String^ serverName){
03
04 ServiceController^ crtl = gcnew
05 ServiceController(“FileService”);
06 if (crtl->Status == ServiceControllerStatus::Stopped){}
07 }
You need to develop a routine that will start FileService if it stops. The routine must start
FileService on the server identified by the serverName input parameter.
Which two lines of code should you add to the code segment? (Each correct answer presents
part of the solution. Choose two.)
A. Insert the following line of code between lines 03 and 04:crtl.ServiceName = serverName;
B. Insert the following line of code between lines 03 and 04:crtl.MachineName = serverName;
C. Insert the following line of code between lines 03 and 04:crtl.Site.Name = serverName;
D. Insert the following line of code between lines 04 and 05:crtl.Continue();
E. Insert the following line of code between lines 04 and 05:crtl.Start();
F. Insert the following line of code between lines 04 and 05:crtl.ExecuteCommand(0);
Answer: B, E
multiple servers on your network. You implement the following code segment. (Line numbers are
included for reference only.)
01 public :
02 void StartService(String^ serverName){
03
04 ServiceController^ crtl = gcnew
05 ServiceController(“FileService”);
06 if (crtl->Status == ServiceControllerStatus::Stopped){}
07 }
You need to develop a routine that will start FileService if it stops. The routine must start
FileService on the server identified by the serverName input parameter.
Which two lines of code should you add to the code segment? (Each correct answer presents
part of the solution. Choose two.)
A. Insert the following line of code between lines 03 and 04:crtl.ServiceName = serverName;
B. Insert the following line of code between lines 03 and 04:crtl.MachineName = serverName;
C. Insert the following line of code between lines 03 and 04:crtl.Site.Name = serverName;
D. Insert the following line of code between lines 04 and 05:crtl.Continue();
E. Insert the following line of code between lines 04 and 05:crtl.Start();
F. Insert the following line of code between lines 04 and 05:crtl.ExecuteCommand(0);
Answer: B, E
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?
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. public ref class MYDictionary : public Dictionary<String^, String^>{};
B. public ref class MYDictionary : public Hashtable{};
C. public ref class MYDictionary : public IDictionary{};
D. public ref class MYDictionary {};Distionary<String^, String^>t = gcnew Dictionary<String^,
String^>();MyDictionary dictionary = (MyDictionary)t;
Answer: A
MyDictionary. You need to ensure that the dictionary is type safe.
Which code segment should you use?
A. public ref class MYDictionary : public Dictionary<String^, String^>{};
B. public ref class MYDictionary : public Hashtable{};
C. public ref class MYDictionary : public IDictionary{};
D. public ref class MYDictionary {};Distionary<String^, String^>t = gcnew Dictionary<String^,
String^>();MyDictionary dictionary = (MyDictionary)t;
Answer: A
You are defining a class named BraindumpsClass that contains several child objects.
You are defining a class named BraindumpsClass that contains several child objects.
BraindumpsClass contains a method named ProcessChildren that performs actions on the child
objects. BraindumpsClass objects will be serializable.
You need to ensure that the ProcessChildren method is executed after the BraindumpsClass
object and all its child objects are reconstructed.
Which two actions should you perform? (Each correct answer presents part of the solution.
Choose two.)
A. Apply the OnDeserializing attribute to the ProcessChildren method.
B. Specify that BraindumpsClass implements the IDeserializationCallback interface.
C. Specify that BraindumpsClass inherits from the ObjectManager class.
D. Apply the OnSerialized attribute to the ProcessChildren method.
E. Create a GetObjectData method that calls ProcessChildren.
F. Create an OnDeserialization method that calls ProcessChildren.
Answer: B, F
BraindumpsClass contains a method named ProcessChildren that performs actions on the child
objects. BraindumpsClass objects will be serializable.
You need to ensure that the ProcessChildren method is executed after the BraindumpsClass
object and all its child objects are reconstructed.
Which two actions should you perform? (Each correct answer presents part of the solution.
Choose two.)
A. Apply the OnDeserializing attribute to the ProcessChildren method.
B. Specify that BraindumpsClass implements the IDeserializationCallback interface.
C. Specify that BraindumpsClass inherits from the ObjectManager class.
D. Apply the OnSerialized attribute to the ProcessChildren method.
E. Create a GetObjectData method that calls ProcessChildren.
F. Create an OnDeserialization method that calls ProcessChildren.
Answer: B, F
You need to read the entire contents of a file named Message.txt into a single string variable. Which code segment should you use?
You need to read the entire contents of a file named Message.txt into a single string variable.
Which code segment should you use?
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();
Answer: B
Which code segment should you use?
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();
Answer: B
You are writing a method to compress an array of bytes. The array is passed to the method in a parameter named document. You need to compress the incoming array of bytes and return the result as an array of bytes. Which code segment should you use?
You are writing a method to compress an array of bytes. The array is passed to the method in a
parameter named document. You need to compress the incoming array of bytes and return the
result as an array of bytes. Which code segment should you use?
A. MemoryStream^ strm = gcnew MemoryStream(document);
DeflateStream^ deflate = gcnew DeflateStream(strm,
CompressionMode::Compress);
array<Byte>^ result = gcnew array<Byte>(document->Length);
deflate->Write(result, 0, result->Length);
return result;
B. MemoryStream^ strm = gcnew MemoryStream(document);
DeflateStream^ deflate = gcnew DeflateStream(strm,
CompressionMode::Compress);
deflate->Write(document, 0, document->Length);
deflate->Close();return strm->ToArray();
C. MemoryStream^ strm = gcnew MemoryStream();
DeflateStream^ deflate = gcnew
DeflateStream(strm,CompressionMode::Compress);deflate->Write(document, 0, document-
>Length);
deflate->Close();
return strm->ToArray();
D. MemoryStream^ inStream = gcnew MemoryStream(document);DeflateStream^
deflate = gcnew DeflateStream(inStream,
CompressionMode::Compress);
MemoryStream^ outStream = gcnew MemoryStream()
;int b;
while ((b = deflate->ReadByte()) != -1) {
outStream->WriteByte((Byte)b);
}
return outStream->ToArray();
Answer: C
parameter named document. You need to compress the incoming array of bytes and return the
result as an array of bytes. Which code segment should you use?
A. MemoryStream^ strm = gcnew MemoryStream(document);
DeflateStream^ deflate = gcnew DeflateStream(strm,
CompressionMode::Compress);
array<Byte>^ result = gcnew array<Byte>(document->Length);
deflate->Write(result, 0, result->Length);
return result;
B. MemoryStream^ strm = gcnew MemoryStream(document);
DeflateStream^ deflate = gcnew DeflateStream(strm,
CompressionMode::Compress);
deflate->Write(document, 0, document->Length);
deflate->Close();return strm->ToArray();
C. MemoryStream^ strm = gcnew MemoryStream();
DeflateStream^ deflate = gcnew
DeflateStream(strm,CompressionMode::Compress);deflate->Write(document, 0, document-
>Length);
deflate->Close();
return strm->ToArray();
D. MemoryStream^ inStream = gcnew MemoryStream(document);DeflateStream^
deflate = gcnew DeflateStream(inStream,
CompressionMode::Compress);
MemoryStream^ outStream = gcnew MemoryStream()
;int b;
while ((b = deflate->ReadByte()) != -1) {
outStream->WriteByte((Byte)b);
}
return outStream->ToArray();
Answer: C
You create a class library that is used by applications in three departments of your Braindumps.
You create a class library that is used by applications in three departments of your Braindumps.
The library contains a Department class with the following definition.
public class Department {
public string name;
public string manager;
}
Each application uses a custom configuration section to store department-specific values in the
application configuration file as shown in the following code.
<Department>
<name>Hardware</name>
<manager>Braindumps</manager>
</Department>
You need to write a code segment that creates a Department object instance by using the field
values retrieved from the application configuration file. Which code segment should you use?
A. public class deptElement : ConfigurationElement {
protected override void DeserializeElement(
XmlReader reader, bool serializeCollectionKey) {
Department dept = new Department();
dept.name = ConfigurationManager.AppSettings[“name”];
dept.manager =
ConfigurationManager.AppSettings[“manager”];
return dept;
}
}
B. public class deptElement: ConfigurationElement {
protected override void DeserializeElement(
XmlReader reader, bool serializeCollectionKey) {
Department dept = new Department();
dept.name = reader.GetAttribute(“name”);
dept.manager = reader.GetAttribute(“manager”);
}
}
C. public class deptHandler : IConfigurationSectionHandler {
public object Create(object parent, object configContext,
System.Xml.XmlNode section) {
Department dept = new Department();
dept.name = section.SelectSingleNode(“name”).InnerText;
dept.manager =
section.SelectSingleNode(“manager”).InnerText;
return dept;
}
}
D. public class deptHandler : IConfigurationSectionHandler {
public object Create(object parent, object configContext,
System.Xml.XmlNode section) {
Department dept = new Deprtment();
dept.name = section.Attributes[“name”].Value;
dept.manager = section.Attributes[“manager”].Value;
return dept;
}
}
Answer: C
The library contains a Department class with the following definition.
public class Department {
public string name;
public string manager;
}
Each application uses a custom configuration section to store department-specific values in the
application configuration file as shown in the following code.
<Department>
<name>Hardware</name>
<manager>Braindumps</manager>
</Department>
You need to write a code segment that creates a Department object instance by using the field
values retrieved from the application configuration file. Which code segment should you use?
A. public class deptElement : ConfigurationElement {
protected override void DeserializeElement(
XmlReader reader, bool serializeCollectionKey) {
Department dept = new Department();
dept.name = ConfigurationManager.AppSettings[“name”];
dept.manager =
ConfigurationManager.AppSettings[“manager”];
return dept;
}
}
B. public class deptElement: ConfigurationElement {
protected override void DeserializeElement(
XmlReader reader, bool serializeCollectionKey) {
Department dept = new Department();
dept.name = reader.GetAttribute(“name”);
dept.manager = reader.GetAttribute(“manager”);
}
}
C. public class deptHandler : IConfigurationSectionHandler {
public object Create(object parent, object configContext,
System.Xml.XmlNode section) {
Department dept = new Department();
dept.name = section.SelectSingleNode(“name”).InnerText;
dept.manager =
section.SelectSingleNode(“manager”).InnerText;
return dept;
}
}
D. public class deptHandler : IConfigurationSectionHandler {
public object Create(object parent, object configContext,
System.Xml.XmlNode section) {
Department dept = new Deprtment();
dept.name = section.Attributes[“name”].Value;
dept.manager = section.Attributes[“manager”].Value;
return dept;
}
}
Answer: C
You are defining a class named BraindumpsClass that contains several child objects
You are defining a class named BraindumpsClass that contains several child objects.
BraindumpsClass contains a method named ProcessChildren that performs actions on the child
objects. BraindumpsClass objects will be serializable.
You need to ensure that the ProcessChildren method is executed after the BraindumpsClass
object and all its child objects are reconstructed.
Which two actions should you perform? (Each correct answer presents part of the solution.
Choose two.)
A. Apply the OnDeserializing attribute to the ProcessChildren method.
B. Specify that BraindumpsClass implements the IDeserializationCallback interface.
C. Specify that BraindumpsClass inherits from the ObjectManager class.
D. Apply the OnSerialized attribute to the ProcessChildren method.
E. Create a GetObjectData method that calls ProcessChildren.
F. Create an OnDeserialization method that calls ProcessChildren.
Answer: B, F
BraindumpsClass contains a method named ProcessChildren that performs actions on the child
objects. BraindumpsClass objects will be serializable.
You need to ensure that the ProcessChildren method is executed after the BraindumpsClass
object and all its child objects are reconstructed.
Which two actions should you perform? (Each correct answer presents part of the solution.
Choose two.)
A. Apply the OnDeserializing attribute to the ProcessChildren method.
B. Specify that BraindumpsClass implements the IDeserializationCallback interface.
C. Specify that BraindumpsClass inherits from the ObjectManager class.
D. Apply the OnSerialized attribute to the ProcessChildren method.
E. Create a GetObjectData method that calls ProcessChildren.
F. Create an OnDeserialization method that calls ProcessChildren.
Answer: B, F
You are developing a method to call a COM component. You need to use declarative security to explicitly request the runtime to perform a full stack walk.
You are developing a method to call a COM component. You need to use declarative security to
explicitly request the runtime to perform a full stack walk. You must ensure that all callers have
the required level of trust for COM interop before the callers execute your method. Which attribute
should you place on the method?
A. <SecurityPermission( _
SecurityAction.Demand, _
Flags:=SecurityPermissionFlag.UnmanagedCode) _>
B. <SecurityPermission( _
SecurityAction.LinkDemand, _
Flags:=SecurityPermissionFlag.UnmanagedCode) _>
C. <SecurityPermission( _
SecurityAction.Assert, _
Flags:=SecurityPermissionFlag.UnmanagedCode) _>
D. <SecurityPermission( _
SecurityAction.Deny, _
Flags:=SecurityPermissionFlag.UnmanagedCode) _>
Answer: A
explicitly request the runtime to perform a full stack walk. You must ensure that all callers have
the required level of trust for COM interop before the callers execute your method. Which attribute
should you place on the method?
A. <SecurityPermission( _
SecurityAction.Demand, _
Flags:=SecurityPermissionFlag.UnmanagedCode) _>
B. <SecurityPermission( _
SecurityAction.LinkDemand, _
Flags:=SecurityPermissionFlag.UnmanagedCode) _>
C. <SecurityPermission( _
SecurityAction.Assert, _
Flags:=SecurityPermissionFlag.UnmanagedCode) _>
D. <SecurityPermission( _
SecurityAction.Deny, _
Flags:=SecurityPermissionFlag.UnmanagedCode) _>
Answer: A
You write the following custom exception class named CustomException.
You write the following custom exception class named CustomException.
public class CustomException : ApplicationException {
public static int COR_E_ARGUMENT =
unchecked((int)0x80070057);
public CustomException(string msg) : base(msg) {
HResult = COR_E_ARGUMENT;
}} You need to write a code segment that will use the CustomException class to immediately
return control to the COM caller. You also need to ensure that the caller has access to the error
code. Which code segment should you use?
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”);
Answer: D
public class CustomException : ApplicationException {
public static int COR_E_ARGUMENT =
unchecked((int)0x80070057);
public CustomException(string msg) : base(msg) {
HResult = COR_E_ARGUMENT;
}} You need to write a code segment that will use the CustomException class to immediately
return control to the COM caller. You also need to ensure that the caller has access to the error
code. Which code segment should you use?
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”);
Answer: D
You are creating a new security policy for an application domain. You write the following lines of code.
You are creating a new security policy for an application domain. You write the following lines of
code.
Dim objPolicy As PolicyLevel = PolicyLevel.CreateAppDomainLevelDim
noTrustStatement As New PolicyStatement( _
objPolicy.GetNamedPermissionSet("Nothing"))
Dim fullTrustStatement As New PolicyStatement( _
objPolicy.GetNamedPermissionSet("FullTrust"))
You need to arrange code groups for the policy so that loaded assemblies default to the Nothing
permission set. If the assembly originates from a trusted zone, the security policy must grant the
assembly the FullTrust permission set. Which code segment should you use?
A. Dim objGroup1 As CodeGroup = New FirstMatchCodeGroup( _
New ZoneMembershipCondition(SecurityZone.Trusted), _
fullTrustStatement)Dim objGroup2 As CodeGroup = New UnionCodeGroup( _
New AllMembershipCondition, noTrustStatement)
B. Dim objGroup1 As CodeGroup = New FirstMatchCodeGroup( _
New AllMembershipCondition, noTrustStatement)Dim objGroup2 As CodeGroup =
New UnionCodeGroup( _
New ZoneMembershipCondition(SecurityZone.Trusted), _
fullTrustStatement)
C. Dim objGroup As CodeGroup = New UnionCodeGroup( _
New ZoneMembershipCondition(SecurityZone.Trusted), _
fullTrustStatement)
D. Dim objGroup As CodeGroup = New FirstMatchCodeGroup( _
New ZoneMembershipCondition(SecurityZone.Trusted), _
fullTrustStatement)
Answer: B
code.
Dim objPolicy As PolicyLevel = PolicyLevel.CreateAppDomainLevelDim
noTrustStatement As New PolicyStatement( _
objPolicy.GetNamedPermissionSet("Nothing"))
Dim fullTrustStatement As New PolicyStatement( _
objPolicy.GetNamedPermissionSet("FullTrust"))
You need to arrange code groups for the policy so that loaded assemblies default to the Nothing
permission set. If the assembly originates from a trusted zone, the security policy must grant the
assembly the FullTrust permission set. Which code segment should you use?
A. Dim objGroup1 As CodeGroup = New FirstMatchCodeGroup( _
New ZoneMembershipCondition(SecurityZone.Trusted), _
fullTrustStatement)Dim objGroup2 As CodeGroup = New UnionCodeGroup( _
New AllMembershipCondition, noTrustStatement)
B. Dim objGroup1 As CodeGroup = New FirstMatchCodeGroup( _
New AllMembershipCondition, noTrustStatement)Dim objGroup2 As CodeGroup =
New UnionCodeGroup( _
New ZoneMembershipCondition(SecurityZone.Trusted), _
fullTrustStatement)
C. Dim objGroup As CodeGroup = New UnionCodeGroup( _
New ZoneMembershipCondition(SecurityZone.Trusted), _
fullTrustStatement)
D. Dim objGroup As CodeGroup = New FirstMatchCodeGroup( _
New ZoneMembershipCondition(SecurityZone.Trusted), _
fullTrustStatement)
Answer: B
You develop a service application named PollingService that periodically calls long-running procedures.
You develop a service application named PollingService that periodically calls long-running
procedures. These procedures are called from the DoWork method.
You use the following service application code:
Partial Class PollingService Inherits ServiceBase
Dim blnExit As Boolean = False Protected Overrides Sub OnStart(ByVal args() As
String)
Do
DoWork()
Loop While Not blnExit
End Sub
Protected Overrides Sub OnStop()
blnExit = True
End Sub
Private Sub DoWork()
End SubEnd Class
When you attempt to start the service, you receive the following error message: Could not start
the PollingService service on the local computer. Error 1053: The service did not respond to the
start or control request in a timely fashion. You need to modify the service application code so
that the service starts properly. What should you do?
A. Move the loop code into the constructor of the service class from the OnStart method.
B. Drag a timer component onto the design surface of the service. Move the calls to the long-
running procedure from the OnStart method into the Tick event procedure of the timer, set
the Enabled property of the timer to True, and call the Start method of the timer in the
OnStart method.
C. Add a class-level System.Timers.Timer variable to the service class code. Move the call to
the DoWork method into the Elapsed event procedure of the timer, set the Enabled property
of the timer to True, and call the Start method of the timer in the OnStart method.
D. Move the loop code from the OnStart method into the DoWork method.
Answer: C
procedures. These procedures are called from the DoWork method.
You use the following service application code:
Partial Class PollingService Inherits ServiceBase
Dim blnExit As Boolean = False Protected Overrides Sub OnStart(ByVal args() As
String)
Do
DoWork()
Loop While Not blnExit
End Sub
Protected Overrides Sub OnStop()
blnExit = True
End Sub
Private Sub DoWork()
End SubEnd Class
When you attempt to start the service, you receive the following error message: Could not start
the PollingService service on the local computer. Error 1053: The service did not respond to the
start or control request in a timely fashion. You need to modify the service application code so
that the service starts properly. What should you do?
A. Move the loop code into the constructor of the service class from the OnStart method.
B. Drag a timer component onto the design surface of the service. Move the calls to the long-
running procedure from the OnStart method into the Tick event procedure of the timer, set
the Enabled property of the timer to True, and call the Start method of the timer in the
OnStart method.
C. Add a class-level System.Timers.Timer variable to the service class code. Move the call to
the DoWork method into the Elapsed event procedure of the timer, set the Enabled property
of the timer to True, and call the Start method of the timer in the OnStart method.
D. Move the loop code from the OnStart method into the DoWork method.
Answer: C
You are working on a debug build of an application.
You are working on a debug build of an application.
You need to find the line of code that caused an exception to be thrown. Which property of the
Exception class should you use to achieve this goal?
A. Data
B. Message
C. StackTrace
D. Source
Answer: C
You need to find the line of code that caused an exception to be thrown. Which property of the
Exception class should you use to achieve this goal?
A. Data
B. Message
C. StackTrace
D. Source
Answer: C
You create a class library that is used by applications in three departments of your Braindumps. The library contains a Department class with the following definition.
You create a class library that is used by applications in three departments of your Braindumps.
The library contains a Department class with the following definition.
public class Department {
public string name;
public string manager;
}
Each application uses a custom configuration section to store department-specific values in the
application configuration file as shown in the following code.
<Department>
<name>Hardware</name>
<manager>Braindumps</manager>
</Department>
You need to write a code segment that creates a Department object instance by using the field
values retrieved from the application configuration file. Which code segment should you use?
A. public class deptElement : ConfigurationElement {
protected override void DeserializeElement(
XmlReader reader, bool serializeCollectionKey) {
Department dept = new Department();
dept.name = ConfigurationManager.AppSettings[“name”];
dept.manager =
ConfigurationManager.AppSettings[“manager”];
return dept;
}
}
B. public class deptElement: ConfigurationElement {
protected override void DeserializeElement(
XmlReader reader, bool serializeCollectionKey) {
Department dept = new Department();
dept.name = reader.GetAttribute(“name”);
dept.manager = reader.GetAttribute(“manager”);
}
}
C. public class deptHandler : IConfigurationSectionHandler {
public object Create(object parent, object configContext,
System.Xml.XmlNode section) {
Department dept = new Department();
dept.name = section.SelectSingleNode(“name”).InnerText;
dept.manager =
section.SelectSingleNode(“manager”).InnerText;
return dept;
}
}
D. public class deptHandler : IConfigurationSectionHandler {
public object Create(object parent, object configContext,
System.Xml.XmlNode section) {
Department dept = new Deprtment();
dept.name = section.Attributes[“name”].Value;
dept.manager = section.Attributes[“manager”].Value;
return dept;
}
}
Answer: C
You are defining a class named BraindumpsClass that contains several child objects.
You are defining a class named BraindumpsClass that contains several child objects.
BraindumpsClass contains a method named ProcessChildren that performs actions on the child
objects. BraindumpsClass objects will be serializable.
You need to ensure that the ProcessChildren method is executed after the BraindumpsClass
object and all its child objects are reconstructed.
Which two actions should you perform? (Each correct answer presents part of the solution.
Choose two.)
A. Apply the OnDeserializing attribute to the ProcessChildren method.
B. Specify that BraindumpsClass implements the IDeserializationCallback interface.
C. Specify that BraindumpsClass inherits from the ObjectManager class.
D. Apply the OnSerialized attribute to the ProcessChildren method.
E. Create a GetObjectData method that calls ProcessChildren.
F. Create an OnDeserialization method that calls ProcessChildren.
Answer: B, F
BraindumpsClass contains a method named ProcessChildren that performs actions on the child
objects. BraindumpsClass objects will be serializable.
You need to ensure that the ProcessChildren method is executed after the BraindumpsClass
object and all its child objects are reconstructed.
Which two actions should you perform? (Each correct answer presents part of the solution.
Choose two.)
A. Apply the OnDeserializing attribute to the ProcessChildren method.
B. Specify that BraindumpsClass implements the IDeserializationCallback interface.
C. Specify that BraindumpsClass inherits from the ObjectManager class.
D. Apply the OnSerialized attribute to the ProcessChildren method.
E. Create a GetObjectData method that calls ProcessChildren.
F. Create an OnDeserialization method that calls ProcessChildren.
Answer: B, F
You are working on a debug build of an application.
You are working on a debug build of an application.
You need to find the line of code that caused an exception to be thrown. Which property of the
Exception class should you use to achieve this goal?
A. Data
B. Message
C. StackTrace
D. Source
Answer: C
You need to find the line of code that caused an exception to be thrown. Which property of the
Exception class should you use to achieve this goal?
A. Data
B. Message
C. StackTrace
D. Source
Answer: C
You create a class library that is used by applications in three departments of your Braindumps.
You create a class library that is used by applications in three departments of your Braindumps.
The library contains a Department class with the following definition.
Public Class Department
Public name As String
Public manager As String
End Class
Each application uses a custom configuration section to store department-specific values in the
application configuration file as shown in the following code.
<Department>
<name>Hardware</name>
<manager>Braindumps</manager>
</Department>
You need to write a code segment that creates a Department object instance by using the field
values retrieved from the application configuration file. Which code segment should you use?
A. Public Class deptElement
Inherits ConfigurationElement
Protected Overrides Sub DeserializeElement( _
ByVal reader As XmlReader, _
ByVal serializeCollectionKey As Boolean)
Dim dept As Department = New Department()
dept.name = ConfigurationManager.AppSettings("name")
dept.manager = _
ConfigurationManager.AppSettings("manager")
End Sub
End Class
B. Public Class deptElement
Inherits ConfigurationElement
Protected Overrides Sub DeserializeElement( _
ByVal reader As XmlReader, _
ByVal serializeCollectionKey As Boolean)
Dim dept As Department = New Department()
dept.name = reader.GetAttribute("name")
dept.manager = reader.GetAttribute("manager")
End Sub
End Class
C. Public Class deptHandler
Implements IConfigurationSectionHandler
Public Function Create(ByVal parent As Object, _
ByVal configContext As Object, _
ByVal section As System.Xml.XmlNode) As Object _
Implements IConfigurationSectionHandler.Create
Dim dept As Department = new Department()
dept.name = section.SelectSingleNode("name").InnerText
dept.manager = _
section.SelectSingleNode("manager").InnerText
Return dept
End Function
End Class
D. Public Class deptHandler
Implements IConfigurationSectionHandler
Public Function Create(ByVal parent As Object, _
ByVal configContext As Object, _
ByVal section As System.Xml.XmlNode) As Object _
Implements IConfigurationSectionHandler.Create
Dim dept As Department = new Department()
dept.name = section.Attributes("name").Value
dept.manager = section.Attributes("manager").Value
Return dept
End Function
End Class
Answer: C
The library contains a Department class with the following definition.
Public Class Department
Public name As String
Public manager As String
End Class
Each application uses a custom configuration section to store department-specific values in the
application configuration file as shown in the following code.
<Department>
<name>Hardware</name>
<manager>Braindumps</manager>
</Department>
You need to write a code segment that creates a Department object instance by using the field
values retrieved from the application configuration file. Which code segment should you use?
A. Public Class deptElement
Inherits ConfigurationElement
Protected Overrides Sub DeserializeElement( _
ByVal reader As XmlReader, _
ByVal serializeCollectionKey As Boolean)
Dim dept As Department = New Department()
dept.name = ConfigurationManager.AppSettings("name")
dept.manager = _
ConfigurationManager.AppSettings("manager")
End Sub
End Class
B. Public Class deptElement
Inherits ConfigurationElement
Protected Overrides Sub DeserializeElement( _
ByVal reader As XmlReader, _
ByVal serializeCollectionKey As Boolean)
Dim dept As Department = New Department()
dept.name = reader.GetAttribute("name")
dept.manager = reader.GetAttribute("manager")
End Sub
End Class
C. Public Class deptHandler
Implements IConfigurationSectionHandler
Public Function Create(ByVal parent As Object, _
ByVal configContext As Object, _
ByVal section As System.Xml.XmlNode) As Object _
Implements IConfigurationSectionHandler.Create
Dim dept As Department = new Department()
dept.name = section.SelectSingleNode("name").InnerText
dept.manager = _
section.SelectSingleNode("manager").InnerText
Return dept
End Function
End Class
D. Public Class deptHandler
Implements IConfigurationSectionHandler
Public Function Create(ByVal parent As Object, _
ByVal configContext As Object, _
ByVal section As System.Xml.XmlNode) As Object _
Implements IConfigurationSectionHandler.Create
Dim dept As Department = new Department()
dept.name = section.Attributes("name").Value
dept.manager = section.Attributes("manager").Value
Return dept
End Function
End Class
Answer: C
You write the following custom exception class named CustomException.
You write the following custom exception class named 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 SubEnd Class
You need to write a code segment that will use the CustomException class to immediately return
control to the COM caller. You also need to ensure that the caller has access to the error code.
Which code segment should you use?
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")
Answer: D
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 SubEnd Class
You need to write a code segment that will use the CustomException class to immediately return
control to the COM caller. You also need to ensure that the caller has access to the error code.
Which code segment should you use?
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")
Answer: D
You are creating a class to compare a specially-formatted string.
You are creating a class to compare a specially-formatted string. The default collation
comparisons do not apply. You need to implement the IComparable(Of String) interface.
Which code segment should you use?
A. Public Class Person
Implements IComparable(Of String)Public Function CompareTo(ByVal other As String)
As _Integer Implements IComparable(Of String).CompareTo...End FunctionEnd Class
B. Public Class Person
Implements IComparable(Of String)Public Function CompareTo(ByVal other As Object)
As _Integer Implements IComparable(Of String).CompareTo...End FunctionEnd Class
C. Public Class Person
Implements IComparable(Of String)Public Function CompareTo(ByVal other As String)
_As Boolean Implements IComparable(Of String).CompareTo...End FunctionEnd Class
D. Public Class Person
Implements IComparable(Of String)Public Function CompareTo(ByVal other As Object)
_As Boolean Implements IComparable(Of String).CompareTo...End FunctionEnd Class
Answer: A
comparisons do not apply. You need to implement the IComparable(Of String) interface.
Which code segment should you use?
A. Public Class Person
Implements IComparable(Of String)Public Function CompareTo(ByVal other As String)
As _Integer Implements IComparable(Of String).CompareTo...End FunctionEnd Class
B. Public Class Person
Implements IComparable(Of String)Public Function CompareTo(ByVal other As Object)
As _Integer Implements IComparable(Of String).CompareTo...End FunctionEnd Class
C. Public Class Person
Implements IComparable(Of String)Public Function CompareTo(ByVal other As String)
_As Boolean Implements IComparable(Of String).CompareTo...End FunctionEnd Class
D. Public Class Person
Implements IComparable(Of String)Public Function CompareTo(ByVal other As Object)
_As Boolean Implements IComparable(Of String).CompareTo...End FunctionEnd Class
Answer: A
You are developing a custom event handler to automatically print all open documents.
You are developing a custom event handler to automatically print all open documents.
The event handler helps specify the number of copies to be printed. You need to develop a
custom event arguments class to pass as a parameter to the event handler.
Which code segment should you use?
A. public ref class PrintingArgs {
public :
int Copies;
PrintingArgs (int numberOfCopies) {
this->Copies = numberOfCopies;
}};
B. public ref class PrintingArgs : public EventArgs {
public :
int Copies;
PrintingArgs(int numberOfCopies) {
this->Copies = numberOfCopies;
}};
C. public ref class PrintingArgs {
public :
EventArgs Args;
PrintingArgs(EventArgs ea) {
this->Args = ea;
}};
D. public ref class PrintingArgs : public EventArgs {
public :
int Copies;};
Answer: B
The event handler helps specify the number of copies to be printed. You need to develop a
custom event arguments class to pass as a parameter to the event handler.
Which code segment should you use?
A. public ref class PrintingArgs {
public :
int Copies;
PrintingArgs (int numberOfCopies) {
this->Copies = numberOfCopies;
}};
B. public ref class PrintingArgs : public EventArgs {
public :
int Copies;
PrintingArgs(int numberOfCopies) {
this->Copies = numberOfCopies;
}};
C. public ref class PrintingArgs {
public :
EventArgs Args;
PrintingArgs(EventArgs ea) {
this->Args = ea;
}};
D. public ref class PrintingArgs : public EventArgs {
public :
int Copies;};
Answer: B
You are creating an application that retrieves values from a custom section of the application configuration file.
You are creating an application that retrieves values from a custom section of the application
configuration file. The custom section uses XML as shown in the following block.
<ProjectSection name="ProjectBraindumps">
<role name="administrator" />
<role name="manager" />
<role name="support" />
</ProjectSection>
You need to write a code segment to define a class named Role. You need to ensure that the
Role class is initialized with values that are retrieved from the custom section of the configuration file. Which code segment should you use?
A. Public Class RoleInherits ConfigurationElementFriend _ElementName As String =
"name"
<ConfigurationProperty("role")> _
Public ReadOnly Property Name() As String
Get
Return CType(Me("role"), String)
End Get
End PropertyEnd Class
B. Public Class Role
Inherits ConfigurationElement
Friend _ElementName As String = "role"
<ConfigurationProperty("name", IsRequired:=True)> _
Public ReadOnly Property Name() As String
Get
Return CType(Me("name"), String)
End Get
End PropertyEnd Class
C. Public Class Role
Inherits ConfigurationElement
Friend _ElementName As String = "role"
Private _name As String
<ConfigurationProperty("name")> _
Public ReadOnly Property Name() As String
Get
Return _name
End Get
End PropertyEnd Class
D. Public Class Role
Inherits ConfigurationElement
Friend _ElementName As String = "name"
Private _name As String
<ConfigurationProperty("role", IsRequired:=True)> _
Public ReadOnly Property Name() As String
Get
Return _name
End Get
End PropertyEnd Class
Answer: B
configuration file. The custom section uses XML as shown in the following block.
<ProjectSection name="ProjectBraindumps">
<role name="administrator" />
<role name="manager" />
<role name="support" />
</ProjectSection>
You need to write a code segment to define a class named Role. You need to ensure that the
Role class is initialized with values that are retrieved from the custom section of the configuration file. Which code segment should you use?
A. Public Class RoleInherits ConfigurationElementFriend _ElementName As String =
"name"
<ConfigurationProperty("role")> _
Public ReadOnly Property Name() As String
Get
Return CType(Me("role"), String)
End Get
End PropertyEnd Class
B. Public Class Role
Inherits ConfigurationElement
Friend _ElementName As String = "role"
<ConfigurationProperty("name", IsRequired:=True)> _
Public ReadOnly Property Name() As String
Get
Return CType(Me("name"), String)
End Get
End PropertyEnd Class
C. Public Class Role
Inherits ConfigurationElement
Friend _ElementName As String = "role"
Private _name As String
<ConfigurationProperty("name")> _
Public ReadOnly Property Name() As String
Get
Return _name
End Get
End PropertyEnd Class
D. Public Class Role
Inherits ConfigurationElement
Friend _ElementName As String = "name"
Private _name As String
<ConfigurationProperty("role", IsRequired:=True)> _
Public ReadOnly Property Name() As String
Get
Return _name
End Get
End PropertyEnd Class
Answer: B
You need to generate a report that lists language codes and region codes. Which code segment should you use?
You need to generate a report that lists language codes and region codes.
Which code segment should you use?
Which code segment should you use?
A. for each (CultureInfo^ culture in
CultureInfo::GetCultures(CultureTypes::SpecificCultures)) {
// Output the culture information...}
B. CultureInfo^ culture = gcnew CultureInfo(“”); CultureTypes^ types = culture->CultureTypes;
// Output the culture information...
C. for each (CultureInfo^ culture in
CultureInfo::GetCultures(CultureTypes::NeutralCultures)) {
// Output the culture information...}
D. for each (CultureInfo^ culture in
CultureInfo::GetCultures(CultureTypes::ReplacementCultures)) {
// Output the culture information...}
Answer: A
You are creating an undo buffer that stores data modifications. You need to ensure that the undo functionality undoes the most recent data modifications first. You also need to ensure that the undo buffer permits the storage of strings only. Which code segment should you use?
You are creating an undo buffer that stores data modifications. You need to ensure that the undo
functionality undoes the most recent data modifications first. You also need to ensure that the
undo buffer permits the storage of strings only. Which code segment should you use?
functionality undoes the most recent data modifications first. You also need to ensure that the
undo buffer permits the storage of strings only. Which code segment should you use?
A. Stack<String^> undoBuffer = gcnew Stack<String^>();
B. Stack undoBuffer = gcnew Stack();
C. Queue<String^> undoBuffer = gcnew Queue<String^>();
D. Queue undoBuffer = gcnew Queue();
Answer: A
You are developing a class library that will open the network socket connections to computers on the network. You will deploy the class library to the global assembly cache and grant it full trust. You write the following code to ensure usage of the socket connections.
You are developing a class library that will open the network socket connections to computers on
the network. You will deploy the class library to the global assembly cache and grant it full trust.
You write the following code to ensure usage of the socket connections.
the network. You will deploy the class library to the global assembly cache and grant it full trust.
You write the following code to ensure usage of the socket connections.
SocketPermission^ permission =
gcnew SocketPermission(PermissionState::Unrestricted);permission->Assert(); Some of the
applications that use the class library might not have the necessary permissions to open the
network socket connections.
You need to cancel the assertion.
Which code segment should you use?
A. CodeAccessPermission::RevertAssert();
B. CodeAccessPermission::RevertDeny();
C. permission->Deny();
D. permission->PermitOnly();
gcnew SocketPermission(PermissionState::Unrestricted);permission->Assert(); Some of the
applications that use the class library might not have the necessary permissions to open the
network socket connections.
You need to cancel the assertion.
Which code segment should you use?
A. CodeAccessPermission::RevertAssert();
B. CodeAccessPermission::RevertDeny();
C. permission->Deny();
D. permission->PermitOnly();
Answer: A
You are developing a fiscal report for a customer. Your customer has a main office in the United States and a satellite office in Mexico.
You are developing a fiscal report for a customer. Your customer has a main office in the United
States and a satellite office in Mexico.
You need to ensure that when users in the satellite office generate the report, the current date is
displayed in Mexican Spanish format. Which code segment should you use?
A. DataTimeFormatInfo dtfi = new CultureInfo(“es-MX”, false).DateTimeFormat;
DateTime dt = new DateTime(DateTime.Today.Year, DateTime.Today.Month,
DateTime.Today.Day); string dateString = dt.ToString(dtfi.LongDatePattern);
B. Calendar cal = new CultureInfo(“es-MS”, false).Calendar; DateTime dt = new
DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);
Strong dateString = dt.ToString();
C. string dateString = DateTimeFormatInfo.CurrentInfo
GetMonthName(DateTime.Today.Month);
D. string dateString = DateTime.Today.Month.ToString(“es_MX”);
Answer: A
States and a satellite office in Mexico.
You need to ensure that when users in the satellite office generate the report, the current date is
displayed in Mexican Spanish format. Which code segment should you use?
A. DataTimeFormatInfo dtfi = new CultureInfo(“es-MX”, false).DateTimeFormat;
DateTime dt = new DateTime(DateTime.Today.Year, DateTime.Today.Month,
DateTime.Today.Day); string dateString = dt.ToString(dtfi.LongDatePattern);
B. Calendar cal = new CultureInfo(“es-MS”, false).Calendar; DateTime dt = new
DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);
Strong dateString = dt.ToString();
C. string dateString = DateTimeFormatInfo.CurrentInfo
GetMonthName(DateTime.Today.Month);
D. string dateString = DateTime.Today.Month.ToString(“es_MX”);
Answer: A
Implementing and Using an Abstract Class Visual C Sharp 2010
Implementing and Using an Abstract Class Visual C Sharp 2010
1 . . Return to the Drawing project in Visual Studio .
Note A finished working copy of the previous exercise is available in the Drawing project
located in the \Microsoft Press\Visual CSharp Step By Step\Chapter 13\Drawing Using
Interfaces - Complete folder in your Documents folder .
2 . . On the Project menu, click Add Class .
The Add New Item – Drawing dialog box appears .
3 . . In the Name text box, type DrawingShape.cs, and then click Add .
Visual Studio creates the file and displays it in the Code and Text Editor window .
4 . . In the DrawingShape .cs file, add the following using statements to the list at the top:
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Controls;
5 . . The purpose of this class is to contain the code common to the Circle and Square class-
es . A program should not be able to instantiate a DrawingShape object directly . Modify
the definition of the DrawingShape class, and declare it as abstract, as shown here in
bold:
abstract class DrawingShape
{
}
6 . . Add the private variables shown in bold to the DrawingShape class:
abstract class DrawingShape
{
protected int size;
protected int locX = 0, locY = 0;
protected Shape shape = null;
}
The Square and Circle classes both use the locX and locY fields to specify the location of
the object on the canvas, so you can move these fields to the abstract class . Similarly,
the Square and Circle classes both used a field to indicate the size of the object when it
was rendered; although it has a different name in each class (sideLength and radius), se-
mantically the field performed the same task in both classes . The name “size” is a good
abstraction of the purpose of this field .
Internally, the Square class uses a Rectangle object to render itself on the canvas, and
the Circle class uses an Ellipse object . Both of these classes are part of a hierarchy based
on the abstract Shape class in the .NET Framework . The DrawingShape class uses a
Shape field to represent both of these types .
7 . . Add the following constructor to the DrawingShape class:
public DrawingShape(int size)
{
this.size = size;
}
This code initializes the size field in the DrawingShape object .
8 . . Add the SetLocation and SetColor methods to the DrawingShape class, as shown in
bold . These methods provide implementations that are inherited by all classes that
derive from the DrawingShape class . Notice that they are not marked as virtual, and
a derived class is not expected to override them . Also, the DrawingShape class is not
declared as implementing the IDraw or IColor interfaces (interface implementation is
a feature of the Square and Circle classes and not this abstract class), so these methods
are simply declared as public .
abstract class DrawingShape
{
...
public void SetLocation(int xCoord, int yCoord)
{
this.locX = xCoord;
this.locY = yCoord;
}
public void SetColor(Color color)
{
if (shape != null)
{
SolidColorBrush brush = new SolidColorBrush(color);
shape.Fill = brush;
}
}
}
9 . . Add the Draw method to the DrawingShape class . Unlike the previous methods, this
method is declared as virtual, and any derived classes are expected to override it to ex-
tend the functionality . The code in this method verifies that the shape field is not null,
and then draws it on the canvas . The classes that inherit this method must provide thei
own code to instantiate the shape object . (Remember that the Square class creates a
Rectangle object and the Circle class creates an Ellipse object .)
abstract class DrawingShape
{
...
public virtual void Draw(Canvas canvas)
{
if (this.shape == null)
{
throw new ApplicationException(“Shape is null”);
}
this.shape.Height = this.size;
this.shape.Width = this.size;
Canvas.SetTop(this.shape, this.locY);
Canvas.SetLeft(this.shape, this.locX);
canvas.Children.Add(shape);
}
}
You have now completed the DrawingShape abstract class . The next step is to change the
Square and Circle classes so that they inherit from this class, and remove the duplicated code
from the Square and Circle classes .
Interface Restrictions Visual C Sharp 2010
Interface Restrictions Visual C Sharp 2010
The essential idea to remember is that an interface never contains any implementation . The
following restrictions are natural consequences of this:
n You’re not allowed to define any fields in an interface, not even static ones . A field is an
implementation detail of a class or structure .
n You’re not allowed to define any constructors in an interface . A constructor is also
considered to be an implementation detail of a class or structure .
n You’re not allowed to define a destructor in an interface . A destructor contains
the statements used to destroy an object instance .
n You cannot specify an access modifier for any method . All methods in an interface are
implicitly public .
n You cannot nest any types (such as enumerations, structures, classes, or interfaces)
inside an interface .
n An interface is not allowed to inherit from a structure or a class, although an interface
can inherit from another interface . Structures and classes contain implementation; if an interface were allowed to inherit from either, it would be inheriting some implementation .
The essential idea to remember is that an interface never contains any implementation . The
following restrictions are natural consequences of this:
n You’re not allowed to define any fields in an interface, not even static ones . A field is an
implementation detail of a class or structure .
n You’re not allowed to define any constructors in an interface . A constructor is also
considered to be an implementation detail of a class or structure .
n You’re not allowed to define a destructor in an interface . A destructor contains
the statements used to destroy an object instance .
n You cannot specify an access modifier for any method . All methods in an interface are
implicitly public .
n You cannot nest any types (such as enumerations, structures, classes, or interfaces)
inside an interface .
n An interface is not allowed to inherit from a structure or a class, although an interface
can inherit from another interface . Structures and classes contain implementation; if an interface were allowed to inherit from either, it would be inheriting some implementation .
Working with Multiple Interfaces Visual C Sharp 2010
Working with Multiple Interfaces Visual C Sharp 2010
A class can have at most one base class, but it is allowed to implement an unlimited number of interfaces . A class must still implement all the methods it inherits from all its interfaces . If an interface, structure, or class inherits from more than one interface, you write the interfaces in a comma-separated list . If a class also has a base class, the interfaces are listed after the base class . For example, suppose you define another interface named IGrazable that contains the ChewGrass method for all grazing animals . You can define the Horse class like this:
class Horse : Mammal, ILandBound, IGrazable
{
...
}
class Horse : Mammal, ILandBound, IGrazable
{
...
}
Referencing a Class Through Its Interface Visual C Sharp 2010
In the same way that you can reference an object by using a variable defined as a class that is higher up the hierarchy, you can reference an object by using a variable defined as an interface that its class implements . Taking the preceding example, you can reference a Horse object by using an ILandBound variable, as follows:
Horse myHorse = new Horse(...);
ILandBound iMyHorse = myHorse; // legal
This works because all horses are land-bound mammals, although the converse is not true, and you cannot assign an ILandBound object to a Horse variable without casting it first to verify that it does actually reference a Horse object and not some other class that also happens to implement the ILandBound interface .
The technique of referencing an object through an interface is useful because it enables you to define methods that can take different types as parameters, as long as the types implement a specified interface . For example, the FindLandSpeed method shown here can take any argument that implements the ILandBound interface:
int FindLandSpeed(ILandBound landBoundMammal)
{
...
}
Note that when referencing an object through an interface, you can invoke only methods that are visible through the interface .
Horse myHorse = new Horse(...);
ILandBound iMyHorse = myHorse; // legal
This works because all horses are land-bound mammals, although the converse is not true, and you cannot assign an ILandBound object to a Horse variable without casting it first to verify that it does actually reference a Horse object and not some other class that also happens to implement the ILandBound interface .
The technique of referencing an object through an interface is useful because it enables you to define methods that can take different types as parameters, as long as the types implement a specified interface . For example, the FindLandSpeed method shown here can take any argument that implements the ILandBound interface:
int FindLandSpeed(ILandBound landBoundMammal)
{
...
}
Note that when referencing an object through an interface, you can invoke only methods that are visible through the interface .
Implementing an Interface Visual C Sharp 2010
To implement an interface, you declare a class or structure that inherits from the interface and that implements all the methods specified by the interface . For example, suppose you are defining the Mammal hierarchy but you need to specify that land-bound mammals provide a method named NumberOfLegs that returns as an int the number of legs that a mammal has . (Sea-bound mammals do not implement this interface .) You could define the ILandBound interface that contains this method as follows:
interface ILandBound
{
int NumberOfLegs();
}
You could then implement this interface in the Horse class . You inherit from the interface and provide an implementation of every method defined by the interface .
class Horse : ILandBound
{
...
public int NumberOfLegs()
{
return 4;
}
}
interface ILandBound
{
int NumberOfLegs();
}
You could then implement this interface in the Horse class . You inherit from the interface and provide an implementation of every method defined by the interface .
class Horse : ILandBound
{
...
public int NumberOfLegs()
{
return 4;
}
}
Defining an Interface in Visual C Sharp 2010
To define an interface, you use the interface keyword instead of the class or struct keyword . Inside the interface, you declare methods exactly as in a class or a structure except that you never specify an access modifier (public, private, or protected), and you replace the method body with a semicolon .
Here is an example:
Here is an example:
interface IComparable
{
int CompareTo(object obj);
}
well, The Microsoft .NET Framework documentation recommends that you preface the name of your interfaces with the capital letter I . This convention is the last vestige of Hungarian notation in C# . Incidentally, the System namespace already defines the IComparable interface as shown above .
You need to call an unmanaged function from your managed code by using platform invoke services. What should you do?
You need to call an unmanaged function from your managed code by using platform invoke
services. What should you do?
A. Create a class to hold DLL functions and then create prototype methods by using managed
code.
B. Register your assembly by using COM and then reference your managed code from COM.
C. Export a type library for your managed code.
D. Import a type library as an assembly and then create instances of COM object.
Answer: A
services. What should you do?
A. Create a class to hold DLL functions and then create prototype methods by using managed
code.
B. Register your assembly by using COM and then reference your managed code from COM.
C. Export a type library for your managed code.
D. Import a type library as an assembly and then create instances of COM object.
Answer: A
Your application uses two threads, named threadOne and threadTwo.
Your application uses two threads, named threadOne and threadTwo.
You need to modify the code to prevent the execution of threadOne until threadTwo completes
execution.
What should you do?
A. Configure threadOne to run at a lower priority.
B. Configure threadTwo to run at a higher priority.
C. Use a WaitCallback delegate to synchronize the threads.
D. Call the Sleep method of threadOne.
E. Call the SpinLock method of threadOne.
Answer: C
You need to modify the code to prevent the execution of threadOne until threadTwo completes
execution.
What should you do?
A. Configure threadOne to run at a lower priority.
B. Configure threadTwo to run at a higher priority.
C. Use a WaitCallback delegate to synchronize the threads.
D. Call the Sleep method of threadOne.
E. Call the SpinLock method of threadOne.
Answer: C
You need to identify a type that meets the following criteria: ?
You need to identify a type that meets the following criteria: ?
Is always a number.?
Is not greater than 65,535. Which type should you choose?
A. System.UInt16
B. int
C. System.String
D. System.IntPtr
Answer: A
Is always a number.?
Is not greater than 65,535. Which type should you choose?
A. System.UInt16
B. int
C. System.String
D. System.IntPtr
Answer: A
You are writing a method to compress an array of bytes. The array is passed to the method in a parameter named document.
You are writing a method to compress an array of bytes. The array is passed to the method in a
parameter named document. You need to compress the incoming array of bytes and return the
result as an array of bytes. Which code segment should you use?
A. Dim objStream As New MemoryStream(document)
Dim objDeflate As New DeflateStream(objStream, CompressionMode.Compress)
Dim result(document.Length) As Byteobj
Deflate.Write(result, 0, result.Length)Return result
B. Dim objStream As New MemoryStream(document)
Dim objDeflate As New DeflateStream(objStream, CompressionMode.Compress)obj
Deflate.Write(document, 0, document.Length)obj
Deflate.Close()Return objStream.ToArray
C. Dim objStream As New MemoryStream()
Dim objDeflate As New DeflateStream(objStream, CompressionMode.Compress)obj
Deflate.Write(document, 0, document.Length)obj
Deflate.Close()Return objStream.ToArray
D. Dim objStream As New MemoryStream()
Dim objDeflate As New DeflateStream(objStream, CompressionMode.Compress)
Dim outStream As New MemoryStreamDim b As IntegerWhile (b =
objDeflate.ReadByte)
outStream.WriteByte(CByte(b))
End
WhileReturn outStream.ToArray
Answer: C
parameter named document. You need to compress the incoming array of bytes and return the
result as an array of bytes. Which code segment should you use?
A. Dim objStream As New MemoryStream(document)
Dim objDeflate As New DeflateStream(objStream, CompressionMode.Compress)
Dim result(document.Length) As Byteobj
Deflate.Write(result, 0, result.Length)Return result
B. Dim objStream As New MemoryStream(document)
Dim objDeflate As New DeflateStream(objStream, CompressionMode.Compress)obj
Deflate.Write(document, 0, document.Length)obj
Deflate.Close()Return objStream.ToArray
C. Dim objStream As New MemoryStream()
Dim objDeflate As New DeflateStream(objStream, CompressionMode.Compress)obj
Deflate.Write(document, 0, document.Length)obj
Deflate.Close()Return objStream.ToArray
D. Dim objStream As New MemoryStream()
Dim objDeflate As New DeflateStream(objStream, CompressionMode.Compress)
Dim outStream As New MemoryStreamDim b As IntegerWhile (b =
objDeflate.ReadByte)
outStream.WriteByte(CByte(b))
End
WhileReturn outStream.ToArray
Answer: C
You need to write a multicast delegate that accepts a DateTime argument. Which code segment should you use?
You need to write a multicast delegate that accepts a DateTime argument. Which code segment
should you use?
A. public delegate int PowerDeviceOn(bool result,
DateTime autoPowerOff);
B. public delegate bool PowerDeviceOn(object sender,
EventsArgs autoPowerOff);
C. public delegate void PowerDeviceOn(DataTime autoPowerOff);
D. public delegate bool PowerDeviceOn(DataTime autoPowerOff);
Answer: C
should you use?
A. public delegate int PowerDeviceOn(bool result,
DateTime autoPowerOff);
B. public delegate bool PowerDeviceOn(object sender,
EventsArgs autoPowerOff);
C. public delegate void PowerDeviceOn(DataTime autoPowerOff);
D. public delegate bool PowerDeviceOn(DataTime autoPowerOff);
Answer: C
You create an application that stores information about your customers who reside in various regions.
You create an application that stores information about your customers who reside in various
regions. You are developing internal utilities for this application.
You need to gather regional information about your customers in Canada.
Which code segment should you use?
A. For Each objCulture As CultureInfo In
_CultureInfo.GetCultures(CultureTypes.SpecificCultures)
...Next
B. Dim objCulture As New CultureInfo("CA")
...
C. Dim objRegion As New RegionInfo("CA")
...
D. Dim objRegion As New RegionInfo("")If objRegion.Name = "CA" Then
...End If
Answer: C
regions. You are developing internal utilities for this application.
You need to gather regional information about your customers in Canada.
Which code segment should you use?
A. For Each objCulture As CultureInfo In
_CultureInfo.GetCultures(CultureTypes.SpecificCultures)
...Next
B. Dim objCulture As New CultureInfo("CA")
...
C. Dim objRegion As New RegionInfo("CA")
...
D. Dim objRegion As New RegionInfo("")If objRegion.Name = "CA" Then
...End If
Answer: C
You need to generate a report that lists language codes and region codes. Which code segment should you use?
You need to generate a report that lists language codes and region codes.
Which code segment should you use?
A. For Each objCulture As CultureInfo In
_CultureInfo.GetCultures(CultureTypes.SpecificCultures)
...Next
B. Dim objCulture As New CultureInfo("")
Dim objTypes As CultureTypes = obj
Culture.CultureTypes
...
C. For Each objCulture As CultureInfo In
_CultureInfo.GetCultures(CultureTypes.NeutralCultures)
...Next
D. For Each objCulture As CultureInfo In
_CultureInfo.GetCultures(CultureTypes.ReplacementCultures)
...Next
Answer: A
Which code segment should you use?
A. For Each objCulture As CultureInfo In
_CultureInfo.GetCultures(CultureTypes.SpecificCultures)
...Next
B. Dim objCulture As New CultureInfo("")
Dim objTypes As CultureTypes = obj
Culture.CultureTypes
...
C. For Each objCulture As CultureInfo In
_CultureInfo.GetCultures(CultureTypes.NeutralCultures)
...Next
D. For Each objCulture As CultureInfo In
_CultureInfo.GetCultures(CultureTypes.ReplacementCultures)
...Next
Answer: A
You are developing a method to encrypt sensitive data with the Data Encryption Standard (DES) algorithm.
You are developing a method to encrypt sensitive data with the Data Encryption Standard (DES)
algorithm. Your method accepts the following parameters:
The byte array to be encrypted, which is named messageAn encryption key, which is named
keyAn initialization vector, which is named iv
You need to encrypt the data. You also need to write the encrypted data to a MemoryStream
object.
Which code segment should you use?
A. DES^ des = gcnew DESCryptoServiceProvider();
des->BlockSize = message->Length;
ICryptoTransform^ crypto = des->CreateEncryptor(key, iv);
MemoryStream ^cipherStream = gcnew MemoryStream();
CryptoStream ^cryptoStream = gcnew CryptoStream(cipherStream,crypto,
CryptoStreamMode::Write);
cryptoStream->Write(message, 0, message->Length);
B. DES^ des = gcnew DESCryptoServiceProvider();
ICryptoTransform^ crypto = des->CreateDecryptor(key, iv);
MemoryStream ^cipherStream = gcnew MemoryStream();
CryptoStream ^cryptoStream = gcnew CryptoStream(cipherStream, crypto,
CryptoStreamMode::Write);
cryptoStream->Write(message, 0, message->Length);
C. DES^ des = gcnew DESCryptoServiceProvider();ICryptoTransform^ crypto = des-
>CreateDecryptor();
MemoryStream ^cipherStream = gcnew MemoryStream();CryptoStream ^cryptoStream
= gcnew CryptoStream(cipherStream,crypto,
CryptoStreamMode::Write);cryptoStream->Write(message, 0, message->Length);
D. DES^ des = gcnew DESCryptoServiceProvider();ICryptoTransform^ crypto = des-
>CreateEncryptor(key, iv);
MemoryStream ^cipherStream = gcnew MemoryStream();CryptoStream ^cryptoStream
= gcnew CryptoStream(cipherStream, crypto, CryptoStreamMode::Write);
cryptoStream->Write(message, 0, message->Length);
Answer: D
algorithm. Your method accepts the following parameters:
The byte array to be encrypted, which is named messageAn encryption key, which is named
keyAn initialization vector, which is named iv
You need to encrypt the data. You also need to write the encrypted data to a MemoryStream
object.
Which code segment should you use?
A. DES^ des = gcnew DESCryptoServiceProvider();
des->BlockSize = message->Length;
ICryptoTransform^ crypto = des->CreateEncryptor(key, iv);
MemoryStream ^cipherStream = gcnew MemoryStream();
CryptoStream ^cryptoStream = gcnew CryptoStream(cipherStream,crypto,
CryptoStreamMode::Write);
cryptoStream->Write(message, 0, message->Length);
B. DES^ des = gcnew DESCryptoServiceProvider();
ICryptoTransform^ crypto = des->CreateDecryptor(key, iv);
MemoryStream ^cipherStream = gcnew MemoryStream();
CryptoStream ^cryptoStream = gcnew CryptoStream(cipherStream, crypto,
CryptoStreamMode::Write);
cryptoStream->Write(message, 0, message->Length);
C. DES^ des = gcnew DESCryptoServiceProvider();ICryptoTransform^ crypto = des-
>CreateDecryptor();
MemoryStream ^cipherStream = gcnew MemoryStream();CryptoStream ^cryptoStream
= gcnew CryptoStream(cipherStream,crypto,
CryptoStreamMode::Write);cryptoStream->Write(message, 0, message->Length);
D. DES^ des = gcnew DESCryptoServiceProvider();ICryptoTransform^ crypto = des-
>CreateEncryptor(key, iv);
MemoryStream ^cipherStream = gcnew MemoryStream();CryptoStream ^cryptoStream
= gcnew CryptoStream(cipherStream, crypto, CryptoStreamMode::Write);
cryptoStream->Write(message, 0, message->Length);
Answer: D
You write the following code. Public Delegate Sub FaxDocs(ByVal sender As Object, _ ByVal args as FaxArgs) You need to create an event that will invoke FaxDocs. Which code segment should you use?
You write the following code.
Public Delegate Sub FaxDocs(ByVal sender As Object, _
ByVal args as FaxArgs)
You need to create an event that will invoke FaxDocs. Which code segment should you use?
A. Public Shared Event Fax As FaxDocs
B. Public Shared Event FaxDocs As FaxArgs
C. Public Class FaxArgs
Inherits EventArgs
Private coverPageInfo As String
Public Sub New(ByVal coverInfo As String)
Me.coverPageInfo = coverInfo
End Sub
Public ReadOnly Property CoverPageInformation As String
Get
Return Me.coverPageInfo
End Get
End PropertyEnd Class
D. Public Class FaxArgs
Inherits EventArgs
Private coverPageInfo As String
Public ReadOnly Property CoverPageInformation As String
Get
Return Me.coverPageInfo
End Get
End PropertyEnd Class
Answer: A
Public Delegate Sub FaxDocs(ByVal sender As Object, _
ByVal args as FaxArgs)
You need to create an event that will invoke FaxDocs. Which code segment should you use?
A. Public Shared Event Fax As FaxDocs
B. Public Shared Event FaxDocs As FaxArgs
C. Public Class FaxArgs
Inherits EventArgs
Private coverPageInfo As String
Public Sub New(ByVal coverInfo As String)
Me.coverPageInfo = coverInfo
End Sub
Public ReadOnly Property CoverPageInformation As String
Get
Return Me.coverPageInfo
End Get
End PropertyEnd Class
D. Public Class FaxArgs
Inherits EventArgs
Private coverPageInfo As String
Public ReadOnly Property CoverPageInformation As String
Get
Return Me.coverPageInfo
End Get
End PropertyEnd Class
Answer: A
You need to create a dynamic assembly named MyAssembly. You also need to save the assembly to disk. Which code segment should you use?
You need to create a dynamic assembly named MyAssembly. You also need to save the
assembly to disk. Which code segment should you use?
A. Dim objAssembly As New AssemblyName()objAssembly.Name =
"MyAssembly"Dim objBuilder As AssemblyBuilder =
_AppDomain.CurrentDomain.DefineDynamicAssembly( _objAssembly,
AssemblyBuilderAccess.Run)objBuilder.Save("MyAssembly.dll")
B. Dim objAssembly As New AssemblyName()objAssembly.Name =
"MyAssembly"Dim objBuilder As AssemblyBuilder =
_AppDomain.CurrentDomain.DefineDynamicAssembly( _objAssembly,
AssemblyBuilderAccess.Save)objBuilder.Save("MyAssembly.dll")
C. Dim objAssembly As New AssemblyName()objAssembly.Name =
"MyAssembly"Dim objBuilder As AssemblyBuilder =
_AppDomain.CurrentDomain.DefineDynamicAssembly( _objAssembly,
AssemblyBuilderAccess.RunAndSave)objBuilder.Save("MyAssembly.dll")
D. Dim objAssembly As New AssemblyName()objAssembly.Name =
"MyAssembly"Dim objBuilder As AssemblyBuilder =
_AppDomain.CurrentDomain.DefineDynamicAssembly( _objAssembly,
AssemblyBuilderAccess.Save)objBuilder.Save("c:\MyAssembly.dll")
Answer: B
assembly to disk. Which code segment should you use?
A. Dim objAssembly As New AssemblyName()objAssembly.Name =
"MyAssembly"Dim objBuilder As AssemblyBuilder =
_AppDomain.CurrentDomain.DefineDynamicAssembly( _objAssembly,
AssemblyBuilderAccess.Run)objBuilder.Save("MyAssembly.dll")
B. Dim objAssembly As New AssemblyName()objAssembly.Name =
"MyAssembly"Dim objBuilder As AssemblyBuilder =
_AppDomain.CurrentDomain.DefineDynamicAssembly( _objAssembly,
AssemblyBuilderAccess.Save)objBuilder.Save("MyAssembly.dll")
C. Dim objAssembly As New AssemblyName()objAssembly.Name =
"MyAssembly"Dim objBuilder As AssemblyBuilder =
_AppDomain.CurrentDomain.DefineDynamicAssembly( _objAssembly,
AssemblyBuilderAccess.RunAndSave)objBuilder.Save("MyAssembly.dll")
D. Dim objAssembly As New AssemblyName()objAssembly.Name =
"MyAssembly"Dim objBuilder As AssemblyBuilder =
_AppDomain.CurrentDomain.DefineDynamicAssembly( _objAssembly,
AssemblyBuilderAccess.Save)objBuilder.Save("c:\MyAssembly.dll")
Answer: B
You are writing a method to compress an array of bytes. The array is passed to the method in a parameter named document. You need to compress the incoming array of bytes and return the result as an array of bytes. Which code segment should you use?
You are writing a method to compress an array of bytes. The array is passed to the method in a
parameter named document. You need to compress the incoming array of bytes and return the
result as an array of bytes. Which code segment should you use?
A. Dim objStream As New MemoryStream(document)
Dim objDeflate As New DeflateStream(objStream, CompressionMode.Compress)
Dim result(document.Length) As Byteobj
Deflate.Write(result, 0, result.Length)Return result
B. Dim objStream As New MemoryStream(document)
Dim objDeflate As New DeflateStream(objStream, CompressionMode.Compress)obj
Deflate.Write(document, 0, document.Length)obj
Deflate.Close()Return objStream.ToArray
C. Dim objStream As New MemoryStream()
Dim objDeflate As New DeflateStream(objStream, CompressionMode.Compress)obj
Deflate.Write(document, 0, document.Length)obj
Deflate.Close()Return objStream.ToArray
D. Dim objStream As New MemoryStream()
Dim objDeflate As New DeflateStream(objStream, CompressionMode.Compress)
Dim outStream As New MemoryStreamDim b As IntegerWhile (b =
objDeflate.ReadByte)
outStream.WriteByte(CByte(b))
End
WhileReturn outStream.ToArray
Answer: C
parameter named document. You need to compress the incoming array of bytes and return the
result as an array of bytes. Which code segment should you use?
A. Dim objStream As New MemoryStream(document)
Dim objDeflate As New DeflateStream(objStream, CompressionMode.Compress)
Dim result(document.Length) As Byteobj
Deflate.Write(result, 0, result.Length)Return result
B. Dim objStream As New MemoryStream(document)
Dim objDeflate As New DeflateStream(objStream, CompressionMode.Compress)obj
Deflate.Write(document, 0, document.Length)obj
Deflate.Close()Return objStream.ToArray
C. Dim objStream As New MemoryStream()
Dim objDeflate As New DeflateStream(objStream, CompressionMode.Compress)obj
Deflate.Write(document, 0, document.Length)obj
Deflate.Close()Return objStream.ToArray
D. Dim objStream As New MemoryStream()
Dim objDeflate As New DeflateStream(objStream, CompressionMode.Compress)
Dim outStream As New MemoryStreamDim b As IntegerWhile (b =
objDeflate.ReadByte)
outStream.WriteByte(CByte(b))
End
WhileReturn outStream.ToArray
Answer: C
Subscribe to:
Posts (Atom)