Tuesday

70-536 .NET QUESTIONS WITH EXPLANATION

                                    PART 4 OF 10(WITH EXPLANATION)


QUESTION 1

You are changing the security settings of a file named MyData.xml. You need to preserve the existing inherited access rules. You also need to prevent the access rules from inheriting changes in the future. Which code segment should you use?

A. FileSecurity security = new FileSecurity("mydata.xml",AccessControlSections.All);
security.SetAccessRuleProtection(true,true);
File.SetAccessControl("mydata.xml", security);

B. FileSecurity security = new FileSecurity();
security.SetAccessRuleProtection(true,true);
File.SetAccessControl("mydata.xml", security);

C. FileSecurity security = File.GetAccessControl("mydata.xml");
security.SetAccessRuleProtection(true, true);

D. FileSecurity security = File.GetAccessControl("mydata.xml");
security.SetAuditRuleProtection(true,true);
File.SetAccessControl("mydata.xml", security);

Correct Answer: A

Explanation: Retrieve the full access control list for the file, prevent access rules from inheriting in the future
by calling Security.SetAccessRuleProtection(). Finally call File.SetAccessControl() to apply the amended FileSecurity to the file.


QUESTION 2

You are creating a class to compare a specially-formatted string. The default collation comparisons do not
apply. You need to implement the IComparable<string> interface. Which code segment should you use?

A. public class Person : IComparable<string>
{
public int CompareTo(string other) { }
}

B. public class Person : IComparable<string>
{
public int CompareTo(object other) { }
}

C. public class Person : IComparable<string>
{
public bool CompareTo(string other) { }
}

D. public class Person : IComparable<string>
{
public bool CompareTo(object other) { }
}

Correct Answer: A

QUESTION 3

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)]

Correct Answer: A

Explanation: A Demand should be used on the SecurityPermission attribute with the UnmanagedCode flag to force all callers in the call stack to have permission to call unmanaged components.
LinkDemand will only force the immediate caller to have the permission.
Assert will ignore the permissions of callers and allow them indiscriminately.
Deny will explicitly deny access if the caller has the specified permission. This is the reverse of what is
required.

QUESTION 4

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. AppDomainSetup mySetup = AppDomain.CurrentDomain.SetupInformation; mySetup.ShadowCopyFiles =
"true";

B. System.Diagnostics.Process myProcess;
myProcess = new System.Diagnostics.Process();

C. AppDomain domain;
domain = AppDomain.CreateDomain("CompanyDomain"):

D. System.ComponentModel.Component myComponent;
myComponent = new System.ComponentModel.Component();

Correct Answer: C

Explanation: Create a new ApplicationDomain using the AppDomain.CreateDomain() method.

QUESTION 5

You need to create a method to clear a Queue named q. Which code segment should you use?

A. foreach (object e in q) {
Dequeue();
}

B. foreach (object e in q) {
Enqueue(null);
}

C. q.Clear();

D. q.Dequeue();

Correct Answer: C

Explanation:Simply call the Clear() method to empty a queue.
Incorrect Answers
* Dequeuing all of the items in a queue will also serve the same affect but it is a lot more roundabout.
* attempts to re-queue items that are already in the queue
* q.Dequeue will de-queue only one item that is at the front of the queue.

QUESTION 6

You are testing a method that examines a running process. This method returns an ArrayList containing the name and full path of all modules that are loaded by the process. You need to list the modules loaded by a process named C:\TestApps\Process1.exe. Which code segment should you use?

A. ArrayList ar = new ArrayList();
Process[] procs;
ProcessModuleCollection modules;
procs = Process.GetProcesses(@"Process1");
if (procs.Length > 0)
{
modules = porcs[0].Modules;
foreach (ProcessModule mod in modules)
{
ar.Add(mod.ModuleName);
}}

B. ArrayList ar = new ArrayList();
Process[] procs;
ProcessModuleCollection modules;
procs = Process.GetProcesses(@"C:\TestApps\Process1.exe");
if (procs.Length > 0)
{
modules =porcs[0].Modules;
foreach (ProcessModule mod in modules)
{
ar.Add(mod.ModuleName);
}}

C. ArrayList ar = new ArrayList();
Process[] procs;
ProcessModuleCollection modules;
procs = Process.GetProcessesByName(@"Process1");
if (procs.Length > 0)
{
modules = porcs[0].Modules;
foreach (ProcessModule mod in modules)
{
ar.Add(mod.FileName);
}}

D. ArrayList ar = new ArrayList();Process[] procs;
ProcessModuleCollection modules;procs = Process.GetProcessesByName(@"C:\TestApps\Process1.
exe");
if (procs.Length > 0)
{
modules = porcs[0].Modules;
foreach (ProcessModule mod in modules)
{
ar.Add(mod.FileName);
}}

Correct Answer: C

Explanation: Process.GetProcessesByName() should be used to return all the processes that match a process name. The modules collection exposes all the modules loaded by the process and can be added to an ArrayList.

QUESTION 7

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);

Correct Answer: C

QUESTION 8

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. Calendar cal = new CultureInfo("es-MX", false).Calendar;
DateTime dt = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);
Strong dateString = dt.ToString();

B. string dateString = DateTime.Today.Month.ToString("es-MX");

C. string dateString = DateTimeFormatInfo.CurrentInfo
GetMonthName(DateTime.Today.Month);

D. DateTimeFormatInfo 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);

Correct Answer: D

Explanation: Create a Mexican Spanish CultureInfo object. Convert the date to a string using the DateTimeFormatInfo returned by the CultureInfo object.

QUESTION 9

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");

Correct Answer: D

QUESTION 10

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;

Correct Answer: D

QUESTION 11

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);

Correct Answer: B

Explanation: BitVector32 is more efficient than a BitArray when 32 or less binary flags are required. Primarily because it is a value type.

QUESTION 12

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


Correct Answer: B

Explanation: Create a StreamReader based on the file and call the ReadToEnd() method to quickly read the entire file and return a string.

CLICK FOR PART 5 OF 10
CLICK FOR PART 1 OF 10

No comments:

Post a Comment