Monday, August 31, 2009

70-536 MCTS .NET Foundations Questions #36

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 & not sure the answers are correct. There were over 200 questions & some duplicates, I hope to study all of them. 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.

Whew! 211 Questions reviewed!

Thx,

Catto

Q: #186 - #211

Question: 186

You are writing code for user authentication and authorization. The username, password, and roles are stored in your application data store. You need to establish a user security context that will be used for authorization checks such as IsInRole. You write the following code segment to authorize the user.

If TestPassword(UserName, Password) = False Then
Throw New Exception("Could not authenticate user")End If
Dim RolesArray() As String = LookUpUserRoles(UserName)
You need to complete this code so that it establishes the user security context. Which code segment should you use?

A. Dim objID As New GenericIdentity(UserName)
Dim objUser As New GenericPrincipal(objID, RolesArray)
Thread.CurrentPrincipal = objUser

B. Dim objID As New WindowsIdentity(UserName)
Dim objUser As New WindowsPrincipal(objID)
Thread.CurrentPrincipal = objUser

C. Dim objNT As New NTAccount(UserName)
Dim objID As New GenericIdentity(objNT.Value)
Dim objUser As New GenericPrincipal(objID, RolesArray)
Thread.CurrentPrincipal = objUser

D. Dim objToken As IntPtr = IntPtr.Zeroobj
Token = LogonUserUsingInterop(UserName, EncryptedPassword)
Dim objContext As WindowsImpersonationContext =
_WindowsIdentity.Impersonate(objToken)

Answer: A

K8 – Q: Establishes security context A: GenericIdentity GenericPrincipal

Question: 187

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

Answer: B

K8 - File Stream String to end

Question: 188

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

Answer: C

K8 – Q: CLR isolation A: Create AppDomain

Question: 189

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

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

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

C. q.Clear();

D. q.Dequeue();

Answer: C

K8 – ez question right?

Question: 190

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

Dim PersonName as String = "N?el"
Dim Msg as String = "Welcome " + PersonName + "to club ''!"
Dim r As Boolean= 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 Function
MessageBox(ByVal hWnd As Int32, _ByVal text As String, ByVal caption As String, _ByVal t As UInt32) As BooleanEnd Function

B. <DllImport("user32", EntryPoint:="MessageBoxA", _CharSet:=CharSet.Ansi)>
_Public Function MessageBox(ByVal hWnd As Int32,
_<MarshalAs(UnmanagedType.LPWStr)> ByVal text As String,
_<MarshalAs(UnmanagedType.LPWStr)> ByVal caption As String, _ByVal t As UInt32) As BooleanEnd Function

C. <DllImport("user32", CharSet:=CharSet.Unicode)> _Public Function
MessageBox(ByVal hWnd As Int32, _ByVal text As String, ByVal caption As String,
_ByVal t As UInt32) As BooleanEnd Function

D. DllImport("user32", EntryPoint:="MessageBoxA", _CharSet:=CharSet.Unicode)>
_Public Function MessageBox(ByVal hWnd As Int32,

_<MarshalAs(UnmanagedType.LPWStr)> ByVal text As String,

_<MarshalAs(UnmanagedType.LPWStr)> ByVal caption As String, _ByVal t As

UInt32) As BooleanEnd Function

Answer: C

K8 – Q: Marshall String A: CharSet.Unicode

Question: 191

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^ intStream = gcnew MemoryStream(document);
GZipStream^ zipStream = gcnew GZipStream(inStream, CompressionMode::Compress);
array<Byte>^ result = gcnew array<Byte>(document->Length);
zipStream->Write(result, 0, result->Length);
return result;

B. MemoryStream^ stream = gcnew MemoryStream(document);
GZipStream^ zipStream = gcnew GZipStream(stream,

CompressionMode::Compress);
zipStream->Write(document, 0, document- >Length);
zipStream->Close();
return stream->ToArray();

C. MemoryStream^ outStream = gcnew MemoryStream();
GZipStream^ zipStream = gcnew GZipStream(outStream,
CompressionMode::Compress);
zipStream->Write(document, 0, document->Length);
zipStream->Close();
return outStream->ToArray();

D. MemoryStream^ inStream = gcnew MemoryStream(document);
GZipStream^ zipStream = gcnew GZipStream(inStream,
CompressionMode::Compress);
MemoryStream^ outStream = gcnew MemoryStream();
int b;
while ((b = zipStream->ReadByte()) != -1) {
outStream->WriteByte((Byte)b);
} return outStream->ToArray();

Answer: C

K8 – OutStream!

Question: 192

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

K8 - System.Timers.Timer

Question: 193

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

K8 – Q: init to true & min mem A: BitVector32(-1);

Question: 194

You create a method that runs by using the credentials of the end user. You need to use Microsoft Windows groups to authorize the user. You must add a code segment that identifies whether a user is in the local group named Clerk.
Which code segment should you use?

A. WindowsIdentity^ currentUser = WindowsIdentity::GetCurrent();
For each
(IdentityReference^ grp in currentUser->Groups) {

NTAccount^ grpAccount =
safe_cast<NTAccount^>(grp->Translate(NTAccount::typeid));
isAuthorized = grpAccount->Value->Equals(
Environment::MachineName + “\\Clerk”);
if(isAuthorized) break;}

B. WindowsPrincipal^ currentUser =
safe_cast<WindowsPrincipal^>(Thread::CurrentPrincipal);
isAuthorized = currentUser->IsInRole(“Clerk”);

C. GenericPrincipal^ currentUser = safe_cast<GenericPrincipal^>(Thread::CurrentPrincipal);
isAuthorized = currentUser->IsInRole(“Clerk”);

D. WindowsPrincipal^ currentUser = safe_cast<WindowsPrincipal^>(Thread::CurrentPrincipal);
isAuthorized = currentUser->IsInRole( Environment::MachineName);

Answer: B

K8 – Q: Identify if user is in local user group A: WindowsPrincipal IsInRole(“rolename”)

Question: 195

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

K8 – Sorting w/ IComparable

Question: 196

You write a class named Employee that includes the following code segment.
public ref
class Employee{
String^ employeeId;
String^ employeeName;
String^ jobTitleName;
public: String^ GetName() { return employeeName; }
String^ GetJobTitle() { return jobTitleName; }

You need to expose this class to COM in a type library. The COM interface must also facilitate forward-compatibility 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

{

Answer: D

K8 – Define an interface

Question: 197

You are developing a method to hash data for later verification by using the MD5 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 MD5. You also need to place the result into a byte array. Which code segment should you use?

A. HashAlgorithm ^algo = HashAlgorithm::Create(“MD5”);
hash = algo->CompueHash(message);

B. HashAlgorithm ^algo = HashAlgorithm::Create(“MD5”);
hash = BitConverter::GetBytes(algo->GetHashCode());

C. HashAlgorithm ^algo;
algo = HashAlgorithm::Create(message->ToString());
hash = algo->Hash;

D. HashAlgorithm ^algo = HashAlgorithm::Create(“MD5”);
hash = nullptr;
algo->TransformBlock(message, 0, message->Length, hash, 0);

Answer: A

K8 – Q: Compute Hash A: ComputeHash

1 comment:

Anonymous said...

About question 197, the message comes in a byte array, and not in a stream array, so it should be answer D