Latest MCTS 70-536 Real Exam Download 41-50

Ensurepass

QUESTION 41

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 : ServiceBase

{

bool blnExit = false; public PollingService() {}

protected override void OnStart(string[] args)

{

do { DoWork();} while (!blnExit);

}

protected override void OnStop() { blnExit = true; } private void DoWork() { …}

}

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 longrunning 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.

Correct Answer: C


QUESTION 42

You need to write a code segment that transfers the contents of a byte array named dataToSend by using a NetworkStream object named netStream. You need to use a cache of size 8,192 bytes.

Which code segment should you use?

A. MemoryStream memStream = new MemoryStream(8192);

memStream.Write(dataToSend, 0, (int) netStream.Length);

B. MemoryStream memStream = new MemoryStream(8192); netStream.Write(dataToSend, 0, (int) memStream.Length);

C. BufferedStream bufStream = new BufferedStream(netStream, 8192); bufStream.Write(dataToSend, 0, dataToSend.Length);

D. BufferedStream bufStream = new BufferedStream(netStream); bufStream.Write(dataToSend, 0, 8192);

Correct Answer: C


QUESTION 43

You are developing a method that searches a string for a substring. The method will be localized to Italy.

Your method accepts the following parameters:

稵he string to be searched, which is named searchList

稵he string for which to search, which is named searchValue.

You need to write the code. Which code segment should you use?

A. return searchList.IndexOf(searchValue);

B. CompareInfo comparer = new CultureInfo("it-IT").CompareInfo; return comparer.Compare(searchList, searchValue);

C. CultureInfo Comparer = new CultureInfo("it-IT"); if (searchList.IndexOf(searchValue) > 0)

{

return true;

}

else

{

return false;

}

D. CompareInfo comparer = new CultureInfo("it-IT").CompareInfo; if (comparer.IndexOf(searchList, searchValue) > 0)

{

return true;

}

else

{

return false;

}

Correct Answer: D


QUESTION 44

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. MemoryStream outStream = new MemoryStream();

GZipStream zipStream = new GZipStream(outStream, CompressionMode.Compress); zipStream.Write(document, 0, document.Length); zipStream.Close();

return outStream.ToArray();

B. MemoryStream inStream = new MemoryStream(document);

GZipStream zipStream = new GZipStream(inStream, CompressionMode.Compress); byte[] result = new byte[document.Length]; zipStream.Write(result, 0, result.Length);

return result;

C. MemoryStream stream = new MemoryStream(document);

GZipStream zipStream = new GZipStream(stream, CompressionMode.Compress); zipStream.Write(document, 0, document.Length); zipStream.Close();

return stream.ToArray();

D. MemoryStream inStream = new MemoryStream(document);

GZipStream zipStream = new GZipStream(inStream, CompressionMode.Compress); MemoryStream outStream = new MemoryStream(); int b;

while ((b = zipStream.ReadByte()) != -1)

{ outStream.WriteByte((byte)b);

}

return outStream.ToArray();

Correct Answer: A


QUESTION 45

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

int rc = MessageBox(hWnd, text, caption, type);

You need to define a method prototype. Which code segment should you use?

A. [DllImport("user32")]

public static extern int MessageBox(int hWnd, String text,String caption, uint type);

B. [DllImport("user32")]

public static extern int MessageBoxA(int hWnd, String text,String caption, uint type);

C. [DllImport("user32")]

public static extern int Win32API_User32_MessageBox(int hWnd, String text, String caption, uint type);

D. [DllImport(@"C:\WINDOWS\system32\user32.dll")]

public static extern int MessageBox(int hWnd, String text,String caption, uint type);

Correct Answer: A


QUESTION 46

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="ProjectCompany">

<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 Role : ConfigurationElement

{

internal string ElementName = "name"; [ConfigurationProperty("role")]

public string Name

{

get { return ((string)base["role"]); }

}

}

B. public class Role : ConfigurationElement

{

internal string ElementName = "role"; [ConfigurationProperty("name", RequiredValue = true)] public string Name

{

get { return ((string)base["name"]); }

}

}

C. public class Role : ConfigurationElement

{

internal string ElementName = "role"; private String name; [ConfigurationProperty("name")] public string Name

{

get { return name; }

}

}

D. public class Role : ConfigurationElement

{

internal string ElementName = "name"; private String name;

[ConfigurationProperty("role", RequiredValue = true)] public string Name

{

get { return name; }

}

}

Correct Answer: B


QUESTION 47

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 "Company"

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 == "Company", "Test Failed: ", fName);

B. Debug.WriteLineIf(fName != "Company", fName, "Test Failed");

C. if (fName != "Company")

{

Debug.Print("Test Failed: "); Debug.Print(fName);

}

D. if (fName != "Company")

{

Debug.WriteLine("Test Failed: "); Debug.WriteLine(fName);

}

Correct Answer: B


QUESTION 48

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(newWindowsPrincipal(null));

C. AppDomain domain = AppDomain.CurrentDomain; domain.SetAppDomainPolicy(PolicyLevel.CreateAppDomainLevel());

D. AppDomain domain = AppDomain.CurrentDomain; domain.SetPrincipalPolicy(PrincipalPolicy.UnauthenticatedPrincipal);

Correct Answer: D


QUESTION 49

You write a class named Employee that includes the following code segment.

public class Employee

{

string employeeId, string employeeName, string jobTitleName;

public string GetName() { return employeeName; } public string GetTitle() { return jobTitleName; }

}

You need to expose this class to COM in a type library. The COM interface must also facilitate forwardcompatibility across new versions of the Employee class. You need to choose a method for generating the COM interface.

What should you do?

A. Add the following attribute to the class definition. [ClassInterface(ClassInterfaceType.None)] public class Employee

{

B. Add the following attribute to the class definition. [ClassInterface(ClassInterfaceType.AutoDual)] public class Employee

{

C. Add the following attribute to the class definition. [ComVisible(true)]

public class Employee

{

D. Define an interface for the class and add the following attribute to the class definition. [ClassInterface(ClassInterfaceType.None)]

public class Employee : IEmployee

{

Correct Answer: D


QUESTION 50

You need to write a multicast delegate that accepts a DateTime argument and returns a Boolean value. Which code segment should you use?

A. public delegate int PowerDeviceOn(bool,DateTime);

B. public delegate bool PowerDeviceOn(Object,EventArgs);

C. public delegate void PowerDeviceOn(DateTime);

D. public delegate bool PowerDeviceOn(DateTime);

Correct Answer: A

Download Latest 70-536 Real Free Tests , help you to pass exam 100%.