Monday, August 24, 2009

70-536 MCTS .NET Foundations #26

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.

Thx,

Catto

Q#100 – Q#110

#26 below

Question: 100

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))
throw new Exception(“could not authenticate user”);
String[] userRolesArray = LookupUserRoles(userName);
You need to complete this code so that it establishes the user
security context.
Which code segment should you use?

A. GenericIdentity ident = new GenericIdentity(userName);
GenericPrincipal currentUser = New GenericPrincipal(ident, userRolesArray);
Thread.CurrentPrincipal = currentUser;

B. WindowsIdentity ident = new WindowsIdentity(userName);
WindowsPrincipal currentUser = new WindowsPrincipal(ident);
Thread.CurrentPrincipal = currentUser;

C. NTAccount userNTName = new NTAccount(userName);
GenericIdentity ident = new enericIdentity(userNTName.Value);
GenericPrincipal currentUser = new GenericPrincipal(ident, userRolesArray);
Thread.CurrentPrincipal = currentUser;

D. IntPtr token = IntPtr.Zero;token = LogonUserUsingInterop(username, encryptedPassword);
WindowsImpersonationContext ctx = WindowsIdentity.Impersonate(token);

Answer: A

K8 – GenericIdentity

Question: 101

You create an application that stores information about your customers who reside in various regions. You are developing internal utilities for this application. You need to gather regional information about your customers in Canada. Which code segment should you use?

A. For Each objCulture As CultureInfo In
_CultureInfo.GetCultures(CultureTypes .SpecificCultures)
...Next

B. Dim objCulture As New CultureInfo("CA")

C. Dim objRegion As New RegionInfo("CA")

D. Dim objRegion As New RegionInfo("")If objRegion.Name = "CA" Then

...End If

Answer: C

Gather regional information RegionInfo

Question: 102

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(“me@Company.com”, “Me”);
MailAddress addrTo(“you@Company.com”, “You”);
MailMessage message(%addrFrom, %addrTo);
message.Subject = “Greetings!”;
message.Body = “Test”;message.Dispose();

B. String^strSmtpClient = “smtp.Company.com”;
String^ strFrom = “me@Company.com”;
String^ strTo = “you@Company.com”;
String^ strSubject = “Greetings!”;String^ strBody = “Test”;
MailMessage msg(strFrom, strTo, strSubject, strSmtpClient);

C. MailAddress addrFrom(“me@Company.com”);
MailAddress addrTo(“you@Company.com”);
MailMessage message(%addrFrom, %addrTo);
message.Subject = “Greetings!”;
message.body = “Test”;SmtpClient lient(“smtp.Company.com”);
client.Send(%message);

D. MailAddress^ addrFrom = gcnew MailAddress(“me@Company.com”, “Me”);
MailAddress^ addrTo = gcnew MailAddress(“you@Company.com”, “You”);
MailMessage^ message = gcnew MailMessage(addrFrom, addrTo);
message->Subject = “Greetings!”;
message->Body = “Test”;
SocketInformation info;
Socket^ client = gcnew Socket(info);
System::Text::ASCIIEncoding^ enc = gcnew System::Text::ASCIIEncoding();
array<unsigned char>^ msgBytes = enc-
>GetBytes(message->ToString());
client->Send(msgBytes);

Answer: C

K8 - Need sent at end

Question: 103

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, ms g, 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)]extern bool MessageBox(int hWnd,
String^ text,
String^ caption,
unsigned int type);}

B. [DllImport("user32", EntryPoint = "MessageBoxA", CharSet = CharSet::Ansi)]extern
bool MessageBox(int hWnd,
[MarshalAs(UnmanagedType::LPWStr)]String^ text,
[MarshalAs(UnmanagedType::LPWStr)]String^ caption,
unsigned int type);}

C. [DllImport("user32", CharSet = CharSet::Unicode)]extern bool MessageBox(int hWnd,
String^ text,
String^ caption,
unsigned int type);}

D. [DllImport("user32", EntryPoint = "MessageBoxA", CharSet =
CharSet::Unicode)]extern bool MessageBox(int hWnd,
[MarshalAs(UnmanagedType.LPWStr)]String^ text,
[MarshalAs(UnmanagedType.LPWStr)]String^ caption,
unsigned int type);}

Answer: C

K8 – Q: best marshal the string data. A: Unicode CharSet

Question: 104

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 ref class Role : public ConfigurationElement {
protected :
static String^ _ElementName = “name”;
public :
[ConfigurationProperty("role")]
property String^ Name {
String^ get() {return ((String^)base[“role”]);}

}};

B. public ref class Role : public ConfigurationElement {
protected :
static String^ _ElementName = “role”;
public :
[ConfigurationProperty("name", IsRequired = true)]
property String^ Name {
String^ get() {return ((String^)base[“name”]);}
}};

C. public ref class Role : public ConfigurationElement {
private :
String^ _name;
protected :
static String^ _ElementName = “role”;
public :
[ConfigurationProperty("name")]
property String^ Name {
String^ get() {return_name;}
}};

D. public ref class Role : public ConfigurationElement {
private :
String^ _name;
protected :
static String^ _ElementName = “name”;
public :
[ConfigurationProperty("role", IsRequired = true)]
property String^ Name {
String^ get() {return_name;}
}};

Answer: B

K8 - ElementName role & protected

Question: 105

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();
foreach
(IdentityReference grp in currentUser.Groups) {
NTAccount grpAccount =
((NTAccount)grp.Translate(typeof(NTAccount)));
isAuthorized = grpAccount.Value.Equals(Environment.MachineName + @”\Clerk”);
if(isAuthorized) break;}

B. WindowsPrincipal currentUser =
(WindowsPrincipal)Thread.CurrentPrincipal;
isAuthorized = currentUser.IsInRole(“Clerk”);

C. GenericPrincipal currentUser =
(GenericPrincipal) Thread.CurrentPrincipal;
isAuthorized = currentUser.IsInRole(“Clerk”):

D. WindowsPrincipal currentUser =
(WindowsPrincipal)Thread.CurrentPrincipal;
isAuthorized = currentUser.IsInRole(Environment.MachineName);

Answer: B

K8 – Authorize user & user in local group WindowsPrincipal

Question: 106

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. Dim MailFrom As New MailAddress("me@Company.com", "Me")
Dim MailTo As New MailAddress("you@Company.com", "You")
Dim Message As New MailMessage(MailFrom, MailTo)Message.Subject =
"Greetings"Message.Body = "Test"Message.Dispose()

B. Dim SMTPClient As String = "smtp.Company.com"
Dim MailFrom As String = me@Company.com
Dim MailTo As String = you@Company.com
Dim Subject As String = "Greetings"
Dim Body As String = "Test"Dim Message As New MailMessage(MailFrom, MailTo, Subject, SMTPClient)

C. Dim MailFrom As New MailAddress("me@Company.com", "Me")
Dim MailTo As New MailAddress("you@Company.com", "You")
Dim Message As New MailMessage(MailFrom, MailTo)Message.Subject =
"Greetings"Message.Body = "Test"
Dim objClient As New SmtpClient("smtp.Company.com")objClient.Send(Message)

D. Dim MailFrom As New MailAddress("me@Company.com", "Me")

Dim MailTo As New MailAddress("you@Company.com", "You")
Dim Message As New MailMessage(MailFrom, MailTo)Message.Subject =
"Greetings"Message.Body = "Test"
Dim Info As New SocketInformationDim Client As New Socket(Info)
Dim Enc As New ASCIIEncodingDim Bytes() As Byte =
Enc.GetBytes(Message.ToString)Client.Send(Bytes)

Answer: C

K8 – Send email objClient.Send(

Question: 107

You need to write a code segment that performs the following tasks: Retrieves the name of each paused service. Passes the name to the Add method of Collection1. Which code segment should you use?

A. ManagementObjectSearcher searcher =
new ManagementObjectSearcher(
“Select * from Win32_Service where State = ‘Paused’”); foreach (ManagementObject svc in searcher.Get()) {
Collection1.Add(svc[“DisplayName”]);}

B. ManagementObjectSearcher searcher =
new ManagementObjectSearcher( "Select * from Win32_Service", "State =
‘Paused’”);foreach (ManagementObject svc in searcher.Get()) { Collection1.Add(svc[“DisplayName”]);}

C. ManagementObjectSearcher searcher =
new ManagementObjectSearcher(
“Select * from Win32_Service”);foreach (ManagemetnObject svc in searcher.Get()) {
if ((string) svc["State"] == "'Paused'") {
Collection1.Add(svc[“DisplayName”]); }}

D. ManagementObjectSearcher searcher =
new ManagementObjectSearcher();searcher.Scope = new
ManagementScope(“Win32_Service”);foreach (ManagementObject svc in
searcher.Get()) {
if ((string)svc["State"] == "Paused") {
Collection1.Add(svc[“DisplayName”]); }}

Answer: A

K8 – inline T-SQL where State = ‘Paused’ will work

Question: 108

You create a class library that is used by applications in three departments of your company. The library contains a Department class with the following definition.

public class Department {
public string name;
public string manager;
}

Each application uses a custom configuration section to store department-specific values in the application configuration file as shown in the following code.

<Department>
<name>Hardware</name>
<manager>Company</manager>
</Department>

You need to write a code segment that creates a Department object instance by using the field values retrieved from the application configuration file. Which code segment should you use?

A. public class deptElement : ConfigurationElement {
protected override void DeserializeElement(
XmlReader reader, bool serializeCollectionKey) {
Department dept = new Department();
dept.name = ConfigurationManager.AppSettings[“name”];
dept.manager =
ConfigurationManager.AppSettings[“manager”];
return dept; } }

B. public class deptElement: ConfigurationElement {
protected override void DeserializeElement(
XmlReader reader, bool serializeCollectionKey) {
Department dept = new Department();
dept.name = reader.GetAttribute(“name”);
dept.manager = reader.GetAttribute(“manager”); } }

C. public class deptHandler : IConfigurationSectionHandler {
public object Create(object parent, object configContext,
System.Xml.XmlNode section) {
Department dept = new Department();
dept.name = section.SelectSingleNode(“name”).InnerText;
dept.manager = section.SelectSingleNode(“manager”).InnerText;
return dept; } }

D. public class deptHandler : IConfigurationSectionHandler {
public object Create(object parent, object configContext,
System.Xml.XmlNode section) {
Department dept = new Deprtment();
dept.name = section.Attributes[“name”].Value;
dept.manager = section.Attributes[“manager”].Value;
return dept; } }

Answer: C

K8 – SelectSingleNode

Question: 109

You need to write a code segment that transfers the first 80 bytes from a stream variable named stream1 into a new byte array named byteArray. You also need to ensure that the code segment assigns the number of bytes that are transferred to an integer variable named bytesTransferred. Which code segment should you use?

A. bytesTransferred = stream1.Read(byteArray, 0, 80);

B. for (int i = 0; i < 80; i++) {
stream1.WriteByte(byteArray[i]);
bytesTransferred = i;
if (!stream1.CanWrite) {
break; }}

C. while (bytesTransferred < 80) {
stream1.Seek(1, SeekOrigin.Current);
byteArray[bytesTransferred++] =
Convert.ToByte(stream1.ReadByte());}

D. stream1.Write(byteArray, 0, 80);
bytesTransferred = byteArray.Length;

Answer: A

K8 – Bytes from stream1 read into byteArray

Question: 110

You are testing a component that serializes the Meeting class instances so that they can be saved to the file system. The Meeting class has the following definition: public ref

class Meeting {
private :
String^ title;
public :
int roomNumber;
array<String^>^ invitees;
Meeting(){}
Meeting(String^ t){
title = t; } };

The component contains a procedure with the following code segment.
Meeting^ myMeeting = gcnew Meeting(“Goals”); myMeeting->roomNumber = 1100;
array<String^>^ attendees = gcnew array<String^>(2)
{“Company”, “Mary”}; myMeeting->invitees = attendees;
XmlSerializer^ xs = gcnew XmlSerializer(__typeof(Meeting));
StreamWriter^ writer = gcnew StreamWriter(“C:\\Meeting.xml”);
xs->Serialize(writer, myMeeting);
writer->Close();

You need to identify the XML block that is written to the C:\Meeting.xml file as a result of running this procedure. Which XML block represents the content that will be written to the C:\Meeting.xml file?

A. <?xml version="1.0" encoding="utf-8"?>
<Meeting xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<title>Goals</title>
<roomNumber>1100</roomNumber>
<invitee>Company</invitee>
<invitee>Mary</invitee>
</Meeting>

B. <?xml version="1.0" encoding="utf-8"?> |
<Meeting xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<roomNumber>1100</roomNumber>
<invitees>
<string>Company</string>
<string>Mary</string>
</invitees>
</Meeting>

C. <?xml version="1.0" encoding="utf-8"?>
<Meeting xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
title="Goals">
<roomNumber>1100</roomNumber>
<invitees>
<string>Company</string>
<string>Mary</string>
</invitees>
</Meeting>

D. <?xml version="1.0" encoding="utf-8"?>
<Meeting xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<roomNumber>1100</roomNumber>
<invitees>
<string>Company</string>
</invitees>
<invitees>

<string>Mary</string>
</invitees>
</Meeting>

Answer: B

No comments: