Saturday, August 22, 2009

70-536 MCTS .NET Question Samples #21

 

Hey Now,

Please feel free to check out my MCTS 70-536 reference page on Chris Catto.com. It’s a page with a summary of all of my posts.
As I study for this test I thought this would be good to post on to learn the content & others would be able to view & comment on it.

This content below is from some practice questions from the internet. I’ve also added some of my notes to these so any line starting with K8 (my nickname, first syllable of Catt o ) are my comments. The questions are numbered from  #13 - #32.

Thx,

Catto

 

Question: 13

You are developing an application for a client residing in Hong Kong. You need to display negative currency values by using a minus sign. Which code segment should you use?

A. Dim objCulture As NumberFormatInfo = _

New CultureInfo("zh-HK").NumberFormatobjCulture.NumberNegativePattern = 1

Return NumberToPrint.ToString("C", objCulture)

B. Dim objCulture As NumberFormatInfo = _

New CultureInfo("zh-HK").NumberFormatobjCulture.CurrencyNegativePattern =

1Return NumberToPrint.ToString("C", objCulture)

Exam Code: 70-536

C. Dim objCulture As NumberFormatInfo = _

New CultureInfo("zh-HK").NumberFormatReturn NumberToPrint.ToString("-{0}",

objCulture)

D. Dim objCulture As NumberFormatInfo = _

New CultureInfo("zh-HK").NumberFormatReturn NumberToPrint.ToString("()",

objCulture)

Answer: B

IF answer is B

NumberFormatobjCulture & CurrencyNegativePattern

for the code is important. Along with 1Return NumberToPrint.ToString("C", objCulture)

Question: 18

You are developing an application for a client residing in Hong Kong. You need to display negative currency values by using a minus sign. Which code segment should you use?

A. NumberFormatInfo^ culture =

gcnew CultureInfo(“zh-HK”)::NumberFormat; culture->NumberNegativePattern = 1;

return numberToPrint->ToString(“C”, culture);

Exam Code: 70-536

B. NumberFormatInfo^ culture =

gcnew CultureInfo(“zh-HK”)::NumberFormat; culture->CurrencyNegativePattern = 1;

return numberToPrint->ToString(“C”, culture);

C. CultureInfo^ culture =

gcnew CultureInfo(“zh-HK”); return numberToPrint->ToString(“-(0)”, culture);

D. CultureInfo^ culture =

gcnew CultureInfo(“zh-HK”); return numberToPrint->ToString(“()”, culture);

Answer: B

K8 – Same question as above but differes a little.

Question: 14

Your application uses two threads, named thread One and thread Two. You need to modify the code to prevent the execution of thread One until thread Two 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

K8- Course – When I’m thinking theading WaitCallback will prevent execution for another thead to complete.

Question: 15

You are developing a method to hash data with the Secure Hash Algorithm. The data is passed to your method as a byte array named message. You need to compute the hash of the incoming parameter by using SHA1. You also need to place the result into a byte array named hash. Which code segment should you use?

A. Dim objSHA As New SHA1CryptoServiceProviderDim hash() As Byte =

NothingobjSHA.TransformBlock(message, 0, message.Length, hash, 0)

B. Dim objSHA As New SHA1CryptoServiceProviderDim hash() As Byte =

BitConverter.GetBytes(objSHA.GetHashCode)

C. Dim objSHA As New SHA1CryptoServiceProviderDim hash() As Byte =

objSHA.ComputeHash(message)

D. Dim objSHA As New SHA1CryptoServiceProviderobjSHA.GetHashCode()Dim

hash() As Byte = objSHA.Hash

Answer: C

K8 – SHA1 – use SHA1CryptoServiceProvider Dim also important for this question objSHA.ComputeHash(message)

Question: 19

You are developing a method to hash data with the Secure Hash Algorithm. The data is passed to your method as a byte array named message. You need to compute the hash of the incoming parameter by using SHA1. You also need to place the result into a byte array named hash. Which code segment should you use?

A. SHA1 ^sha = gcnew SHA1CryptoServiceProvider();array<Byte>^hash = nullptr;sha-

>TransformBlock(message, 0, message->Length, hash, 0);

B. SHA1 ^sha = gcnew SHA1CryptoServiceProvider();array<Byte>^hash =

BitConverter::GetBytes(sha->GetHashCode());

C. SHA1 ^sha = gcnew SHA1CryptoServiceProvider();array<Byte>^hash = sha-

>ComputeHash(message);

D. SHA1 ^sha = gcnew

SHA1CryptoServiceProvider();sha->GetHashCode();array<Byte>^hash = sha->Hash;

Answer: C

K8 – Important SHA1CryptoServiceProvider

Question: 16

You are writing a custom dictionary. The custom-dictionary class is named MyDictionary. You need to ensure that the dictionary is type safe. Which code segment should you use?

A. class MyDictionary : Dictionary<string, string>

B. class MyDictionary : HashTable

C. class MyDictionary : IDictionary

D. class MyDictionary { ... }

Dictionary<string, string> t = new Dictionary<string, string>();MyDictionary dictionary =

(MyDictionary)t;

Answer: A

K8 – Dictionary Type safe so Generics are good maybe? When reading this I didn’t think B could be the answer.

Question: 17

Exam Code: 70-536

You work as a developer at Company.com. You are creating an application that provides information about the local computer. The application contains a form that lists each logical drive

with the drive properties, such as type, volume label, and capacity. You are required to write a procedure that retrieves properties of each logical drive on the local computer.

What should you do?

Arrange the appropriate actions in the correct order.

Answer:

K8 – Hmm this didn’t display too well maybe revisit this question later.

Question: 20

You are writing an application that uses SOAP to exchange data with other applications. You use a Department class that inherits from ArrayList to send objects to another application.

The Department object is named dept. You need to ensure that the application serializes the Department object for transport by using SOAP. Which code should you use?

A. SoapFormatter^ formatter = gcnew SoapFormatter();array<Byte>^ buffer = gcnew

array<Byte>(dept->Capacity);MemoryStream^ stream = gcnew MemoryStream(buffer);

for each (Object^ o in dept) {

formatter->Serialize(stream, o);}

B. SoapFormatter^ formatter = gcnew SoapFormatter();array<Byte>^ buffer = gcnew

array<Byte>(dept->Capacity);MemoryStream^ stream = gcnew MemoryStream(buffer);

formatter->Serialize(stream, dept);

C. SoapFormatter^ formatter = gcnew SoapFormatter();MemoryStream^ stream = gcnew

MemoryStream();for each (Object^ o in dept) {

formatter->Serialize(stream, o);}

D. SoapFormatter^ formatter = gcnew SoapFormatter();MemoryStream^ stream = gcnew

MemoryStream();formatter->Serialize(stream, dept);

Answer: D

K8 - SoapFormatter();MemoryStream^ stream & formatter->Serialize(stream, dept);

Question: 21

You need to write a code segment that will create a common language runtime (CLR) unit of isolation within an application. Which code segment should you use?

A. Dim mySetup As AppDomainSetup = _

AppDomain.CurrentDomain.SetupInformationmySetup.ShadowCopyFiles = "true"

Exam Code: 70-536

B. Dim myProcess As System.Diagnostics.Process myProcess = New

System.Diagnostics.Process()

C. Dim domain As AppDomain domain =

AppDomain.CreateDomain("CompanyDomain")

D. Dim myComponent As System.ComponentModel.ComponentmyComponent = New

System.ComponentModel.Component()

Answer: C

K8 – Isolation in question & AppDomain in answer

Question: 22

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

K8 – Check if the it’s from the “source ” then warning or || Error.

Question: 23

You are developing an application that will use custom authentication and role-based security. You need to write a code segment to make the runtime assign an unauthenticated principal object to each running thread. Which code segment should you use?

A. AppDomain^ domain =

AppDomain::CurrentDomain;domain->

SetPrincipalPolicy(PrincipalPolicy::WindowsPrincipal);

B. AppDomain^ domain =

AppDomain::CurrentDomain;domain->SetThreadPrincipal(gcnew WindowsPrincipal(nullptr));

C. AppDomain^ domain =

AppDomain::CurrentDomain;domain-

>SetAppDomainPolicy(PolicyLevel::CreateAppDomainLevel());

D. AppDomain^ domain =

AppDomain::CurrentDomain;domain-

>SetPrincipalPolicy(PrincipalPolicy::UnauthenticatedPrincipal);

Answer: D

K8 SetPrincipalPolicy along with Unauth

Question: 24

You write the following code. public delegate

void FaxDocs(Object^ sender, FaxArgs^ args); You need to create an event that will invoke FaxDocs. Which code segment should you use?

A. public : static event FaxDocs^ Fax;

B. public : static event Fax^ FaxDocs;

C. public ref class FaxArgs : public EventArgs {

public :

String^ CoverPageInfo;

FaxArgs (String^ coverInfo) {

this->CoverPageInfo = coverInfo;

}};

D. public ref class FaxArgs : public EventArgs {

public :

String^ CoverPageInfo;};

Answer: A

K8 – Public : static event FaxDocs Fax;

Another answer would be I think Public : static event FaxDocs myFaxDocVariable;

Question: 28

You write the following code. public delegate void FaxDocs(object sender, FaxArgs args); You need to create an event that will invoke FaxDocs. Which code segment should you use?

A. pulic static event FaxDocs Fax;

B. public static event Fax FaxDocs;

C. public class FaxArgs : EventArgs {

private string coverPageInfo;

public FaxArgs(string coverInfo) {

this.coverPageInfo = coverPageInfo;

}

public string CoverPageInformation {

get {return this.coverPageInfo;}

}}

D. public class FaxArgs : EventArgs {

private string coverPageInfo;

public string CoverPageInformation {

get {return this.coverPageInfo;}

}}

Answer: A

K8 – Repeat?

Question: 25

You create an application to send a message by e-mail. An SMTP server is available on the local subnet. The SMTP server is named smtp.Company.com. To test the application, you use a source address, me@Company.com, and a target address,

you@Company.com. You need to transmit the e-mail message. Which code segment should you use?

A. MailAddress addrFrom =

new MailAddress(“me@Company.com”, “Me”);MailAddress addrTo =

new MailAddress(“you@Company.com”, “You”);MailMessage message = new

MailMessage(addrFrom, addrTo);message.Subject = “Greetings!”;message.Body =

“Test”;message.Dispose();

B. string strSmtpClient = “mstp.Company.com”;string strFrom = “me@Company.com”;string strTo

= “you@Company.com”;string strSubject = “Greetings!”;string strBody = “Test”;MailMessage

msg = new MailMessage(strFrom, strTo, strSubject, strSmtpClient);

C. MailAddress addrFrom = new MailAddress(“me@Company.com”);MailAddress addrTo = new

MailAddress(“you@Company.com”);MailMessage message = new MailMessage(addrFrom,

addrTo);message.Subject = “Greetings!”;message.Body = “Test”;SmtpClient client = new

SmtpClient(“smtp.Company.com”);client.Send(message);

D. MailAddress addrFrom =

new MailAddress(“me@Company.com”, “Me”);MailAddress addrTo = new

MailAddress(“you@Company.com”, “You”);MailMessage message = new

MailMessage(addrFrom, addrTo);message.Subject = “Greetings!”;message.Body =

“Test”;SocketInformation info = new SocketInformation();Socket client = new

Socket(info);System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();byte[]

msgBytes = enc.GetBytes(message.ToString());client.Send(msgBytes);

Exam Code: 70-536

Answer: C

K8 - SmtpClient( after the MailAddress addForm

Question: 26

You are developing a custom-collection class. You need to create a method in your class. You need to ensure that the method you create in your class returns a type that is compatible with the Foreach statement. Which criterion should the method meet?

A. The method must return a type of either IEnumerator or IEnumerable.

B. The method must return a type of IComparable.

C. The method must explicitly contain a collection.

D. The method must be the only iterator in the class.

Answer: A

K8 – IEnum since For loops need to count

Question: 27

You are developing an application to perform mathematical calculations. You develop a class named CalculationValues. You write a procedure named PerformCalculation that operates on an instance of the class. You need to ensure that the user interface of the application continues to respond while calculations are being performed. You need to write a code segment that calls the PerformCalculation procedure to achieve this goal. Which code segment should you use?

A. private void PerformCalculation() {...} private void DoWork(){

Calculation Values myValues = new Calculation Values();

Thread newThread = new Thread(

new ThreadStart(PerformCalculation));

new Thread.Start(myValues);}

B. private void PerformCalculation() {...} private void DoWork(){

Calculation Values myValues = new Calculation Values();

ThreadStart delStart = new

ThreadStart(PerformCalculation);

Thread newThread = new Thread(delStart);if (newThread.IsAlive)

{newThread.Start(myValues);}}

C. private void PerformCalculation (CalculationValues values) {...} private void

DoWork(){

Calculation Values myValues = new Calculation Values();

Application.DoEvents();

PerformCalculation(myValues);

Application.DoEvents();}

D. private void PerformCalculation(object values) {...} private void DoWork(){

Calculation Values myValues = new Calculation Values();

Thread newThread = new Thread(

new ParameterizedThreadStart(PerformCalculation));

newThread.Start(myValues);}

Answer: D

K8 - Call the procedure & use ParameterizedThreadStart

Question: 29

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 Class PrintingArgs

Private _copies As Integer

Public Sub New(ByVal numberOfCopies As Integer)

Me._copies = numberOfCopies

End Sub

Public ReadOnly Property Copies() As Integer

Get

Return Me._copies

End Get

End PropertyEnd Class

B. Public Class PrintingArgs

Inherits EventArgs

Private _copies As Integer

Public Sub New(ByVal numberOfCopies As Integer)

Me._copies = numberOfCopies

End Sub

Public ReadOnly Property Copies() As Integer

Get

Return Me._copies

End Get

End PropertyEnd Class

C. Public Class PrintingArgs

Private eventArgs As EventArgs

Public Sub New(ByVal args As EventArgs)

Me.eventArgs = args

End Sub

Public ReadOnly Property Args() As EventArgs

Get

Return eventArgs

End Get

End PropertyEnd Class

D. Public Class PrintingArgs

Inherits EventArgs

Private copies As IntegerEnd Class

Answer: B

K8 - Inherits EventArgs

Question: 30

You write the following code segment to call a function from the Win32 Application Programming Interface (API) by using platform invoke. string personName = “N?el”;string msg = “Welcome” + personName + “to club”!”;bool rc =

User32API.MessageBox(0, msg, personName, 0); You need to define a method prototype that can best marshal the string data. Which code segment should you use?

A. [DllImport("user32", CharSet = CharSet.Ansi)]public static extern bool

MessageBox(int hWnd,

String text,

String caption,

uint type);}

B. [DllImport("user32", EntryPoint = "MessageBoxA", CharSet = CharSet.Ansi)]public

static extern bool MessageBox(int hWnd,

[MarshalAs(UnmanagedType.LPWStr)]String text,

[MarshalAs(UnmanagedType.LPWStr)]String caption,

uint type);}

C. [DllImport("user32", CharSet = CharSet.Unicode)]public static extern bool

MessageBox(int hWnd,

String text,

String caption,

uint type);}

D. [DllImport("user32", EntryPoint = "MessageBoxA", CharSet =

CharSet.Unicode)]public static extern bool MessageBox(int hWnd,

[MarshalAs(UnmanagedType.LPWStr)]String text,

[MarshalAs(UnmanagedType.LPWStr)]String caption,

uint type);}

Answer: C

K8 - CharSet.Unicode not asci & not using MarshaAs

Question: 31

You are developing an application that dynamically loads assemblies from an application directory. You need to write a code segment that loads an assembly named Company1.dll into the current application domain. Which code segment should you use?

A. Dim domain As AppDomain = AppDomain.CurrentDomainDim myPath As String =

_ Path.Combine(domain.BaseDirectory, "Company1.dll")Dim asm As [Assembly] =

[Assembly].LoadFrom(myPath)

B. Dim domain As AppDomain = AppDomain.CurrentDomainDim myPath As String = _

Path.Combine(domain.BaseDirectory, "Company1.dll")Dim asm As [Assembly] =

[Assembly].Load(myPath)

C. Dim domain As AppDomain = AppDomain.CurrentDomainDim myPath As String = _

Path.Combine(domain.DynamicDirectory, "Company1.dll")Dim asm As [Assembly] = _

AppDomain.CurrentDomain.Load(myPath)

D. Dim domain As AppDomain = AppDomain.CurrentDomainDim asm As [Assembly]

= domain.GetData("Company1.dll")

Answer: A

K8 - [Assembly].LoadFrom(myPath)

Question: 32

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. Dim result As String = NothingDim reader As New

StreamReader("Message.txt")result = reader.Read().ToString()

B. Dim result As String = NothingDim reader as New

StreamReader("Message.txt")result = reader.ReadToEnd()

C. Dim result As String = string.EmptyDim reader As New

StreamReader("Message.txt")While Not reader.EndOfStream

result &= reader.ToString()End While

D. Dim result as String = NothingDim reader As New

StreamReader("Message.txt")result = reader.ReadLine()

Answer: B

K8 - ReadToEnd will read the entire file.

1 comment:

Anonymous said...

You write the following code segment to call a function from the Win32 Application Programming Interface (API) by using platform invoke.

string personName = “N?el”;
string msg = “Welcome” + personName + “to club”!”;
bool rc = User32API.MessageBox(0, msg, personName, 0);

You need to define a method prototype that can best marshal the string data.

Which code segment should you use?

a)
[DllImport("user32", CharSet = CharSet.Ansi)]
public static extern bool MessageBox(int hWnd, String text, String caption, uint type);
}

or

b)

[DllImport("user32", CharSet = CharSet.Unicode)]
public static extern bool MessageBox(int hWnd, String text, String caption, uint type);
}

I can't understand why the anser is B. Can you help me?