Ensurepass

QUESTION 101

You develop an application that appends text to existing text files. You need to write a code segment that enables the application to append text to a file named C:

MyFile.txt. The application must throw an exception if the file does not exist. You need to ensure that the other applications can read but not modify the file. Which code segment should you use?

A. FileStream fs = new FileStream(@"C:MyFile.txt", FileMode.Open, FileAccess.ReadWrite, FileShare.Read);

B. FileStream fs = new FileStream(@"C:MyFile.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);

C. FileStream fs = new FileStream(@"C:MyFile.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

D. FileStream fs = new FileStream(@"C:MyFile.txt", FileMode.Append, FileAccess.ReadWrite);

Correct Answer: A


QUESTION 102

You are creating a class named Temperature. The Temperature class contains a public field named F. The public field F represents a temperature in degrees Fahrenheit. You need to ensure that users can specify whether a string representation of a Temperature instance displays the Fahrenheit value or the equivalent Celsius value. Which code segment should you use?

A. public class Temperature : IFormattable

{ public int F;

public string ToString (string format, IFormatProvider fp ) { if ((format == "F")|| (format == null)) return F.ToString (); if (format == "C") return ((F – 32) / 1.8). ToString ();

throw new FormatException ("Invalid format string"); }

}

B. public class Temperature : ICustomFormatter

{ public int F;

public string Format(string format, object arg , IFormatProvider fp ) { if (format == "C") return ((F – 32) / 1.8).ToString (); if (format == "F") return arg.ToString (); throw new FormatException ("Invalid format string"); }

}

C. public class Temperature

{ public int F;

public string ToString (string format, IFormatProvider fp ) { if (format == "C") { return ((F – 32) / 1.8). ToString ();

} else {

return this.ToString ();

}

}

}

D. public class Temperature

{ public int F;

protected string format;

public override String ToString ()

{ if (format == "C")

return ((F – 32) / 1.8). ToString (); return F.ToString ();

}

}

Correct Answer: A


QUESTION 103

You are creating an assembly that interacts with the file system. You need to configure a permission request so that the common language runtime (CLR) will stop loading the assembly if the necessary file permissions are absent. Which attribute should you place in your code?

A. [assembly: FileIOPermission(SecurityAction.RequestOptional, AllFiles=FileIOPermissionAccess.Read)]

B. [assembly: FileIOPermission(SecurityAction.RequestRefuse, AllLocalFiles= FileIOPermissionAccess.

Read)]

C. [assembly: FileIOPermission(SecurityAction.RequestMinimum, AllLocalFiles = FileIOPermissionAccess.Read)]

D. [assembly: FileIOPermission(SecurityAction.RequestOptional, AllLocalFiles = FileIOPermissionAccess.

Read)]

Correct Answer: C


QUESTION 104

You are developing a multithreaded application. You need to ensure that a shared resource maintains a consistent state when multiple threads update it. You also need to permit multiple threads to read the shared resource concurrently. What should you do?

A. Use the AcquireWriterLock and ReleaseWriterLock methods of the ReaderWriterLock class when updating the shared resource. Use the AcquireReaderLock and ReleaseReaderLock methods of the ReaderWriterLock class when reading from the shared resource.

B. Always access the resource within a lock statement block.

C. Create a wrapper class to protect the resource and always access the resource by using static methods of the wrapper class.

D. Always use a single-threaded apartment when accessing the resource.

Correct Answer: A


QUESTION 105

You are developing a routine that will periodically perform a calculation based on regularly changing values from legacy systems. You write the following lines of code. (Line numbers are included for reference only.)

01 bool exitLoop = false; 02 do {

4 exitLoop = PerformCalculation();

5 } while (!exitLoop);

You need to write a code segment to ensure that the calculation is performed at 30-second intervals.

You must ensure that minimum processor resources are used between the calculations. Which code segment should you insert at line 03?

A. Thread.Sleep(30000);

B. Thread.SpinWait(30);

C. Thread.SpinWait(30000);

D. Dim thrdCurrent As Thread = Thread.CurrentThread; thrdCurrent.Priority = ThreadPriority.Lowest;

E. Dim thrdCurrent As Thread = Thread.CurrentThread; thrdCurrent.Priority = ThreadPriority.BelowNormal;

Correct Answer: A


QUESTION 106

You create a class library that contains the class hierarchy defined in the following code segment. (Line numbers are included for reference only.)

1 public class Group {

2 public Employee[] Employees; 03 }

04 public class Employee

{ 05 public string Name; 6 }

7 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: [XmlArray(ElementName="Employees")]

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: [XmlArrayItem(Type = typeof(Employee))]

[XmlArrayItem(Type = typeof(Manager))]

D. Insert the following code between lines 3 and 4 of the code segment: [XmlElement(Type = typeof(Employee))]

and

Insert the following code between lines 6 and 7 of the code segment: [XmlElement(Type = typeof(Manager))]

Correct Answer: C


QUESTION 107

You are writing a custom collection class named MyCollection. You need to ensure that the collection is type safe.

Which code segment should you use?

A. class MyCollection: ICollection

B. class MyCollection: ICollection <string>

C. class MyCollection: ArrayList

D. class MyCollection: IComparer <string>

Correct Answer: C


QUESTION 108

You need to write a multicast delegate for an event. The event must also be able to use an EventHandler delegate. Which code segment should you use?

A. public delegate int PowerDeviceOn ( bool result-, DateTime autoPowerOf f );

B. public delegate bool PowerDeviceOn ( DateTime autoPowerOff );

C. public delegate void PowerDeviceOn ( DateTime autoPowerOff );

D. public delegate bool PowerDeviceOn (object sender, EventArgs autoPowerOff ) ;

Correct Answer: D


QUESTION 109

You create a service application that monitors free space on a hard disk drive.

You need to ensure that the service application runs in the background and monitors the free space every minute. What should you do? (Each correct answer presents part of the solution. Choose three.)

A. Add an instance of the System.Windows.Forms.Timer class to the Service class and configure it to fire every minute

B. Add code to the default constructor of the Service class to monitor the free space on the hard disk drive

C. Add code to the Tick event handler of the timer to monitor the free space on the hard disk drive

D. Add code to the OnStart() method of the Service class to monitor the free space on the hard disk drive

E. Add code to the OnStart() method of the Service class to start the timer.

F. Add code to the Elapsed event handler of the timer to monitor the free space on the hard disk drive

G. Add an instance of the System.Timers.Timer class to the Service class and configure it to fire every minute

Correct Answer: EFG


QUESTION 110

You need to ensure that each thread pauses by the number of milliseconds specified in the sleepTime variable. Which code segment should you add at line PO46

of the Poller.cs file?

A. Thread.Sleep(sleepTime);

B. Object wait = "WaitTime"; Thread.VolatileWrite (ref wait, sleepTime);

C. Thread.VolatileRead(ref sleepTime);

D. Thread.SpinWait(sleepTime);

Correct Answer: A

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

Comments are closed.