You are on page 1of 24

 

Practice Questions for Exam 70‐536 
This document contains practice questions that will help you prepare for exam 70-536.

Contents 
Developing Applications That Use System Types and Collections......................................... 1

Implementing Service Processes, Threading, and Application Domains in a .NET


Framework Application ................................................................................................................. 4

Embedding Configuration, Diagnostic, Management, and Installation Features into a


.NET Framework Application ......................................................................................................... 6

Implementing Serialization and Input/Output Functionality in a .NET Framework


Application....................................................................................................................................... 8

Improving the Security of the .NET Framework Applications by Using the .NET Framework
2.0 Security Features..................................................................................................................... 11

Implementing Interoperability, Reflection, and Mailing Functionality in a .NET Framework


Application..................................................................................................................................... 15

Implementing Globalization, Drawing, and Text Manipulation Functionality in a .NET


Framework Application ............................................................................................................... 20

Developing Applications That Use System Types and Collections 
This section contains three practice questions that help prepare you to develop
applications that include system types and collections.

• Question 1
• Question 2
• Question 3

QUESTION 1
You are creating a custom class that allocates large blocks of memory. Instead of
waiting for the runtime to automatically free the resources, you want developers who
use your class to be able to free resources on demand when an instance of the class
is no longer needed. Which interface should you implement?

a) IComparable
b) ICloneable
c) IEquatable
d) IFormattable
e) IDisposable
f) INullableValue
g) IConvertible
ANSWER 1
e) IDisposable

QUESTION 2
What is the purpose of a delegate?

a) To spawn an additional thread to provide parallel processing


b) To copy member methods and properties from an existing class
c) To enable an assembly to respond to an event that occurs within a class
d) To provide identical member methods and properties from multiple related
classes
ANSWER 2
c) To enable an assembly to respond to an event that occurs within a class

QUESTION 3
Which of the following code samples is a valid interface declaration?
a ' VB
) Interface IAsset
Function SampleMethod() As Integer
Dim i As Integer = 5
Return i
End Function
End Interface

// C#
interface ISampleInterface
{
int SampleMethod()
{
int i = 5;
return i;
}
}
b ' VB
) Interface IAsset
Function SampleMethod() as Integer
End Interface

// C#
interface ISampleInterface
{
int SampleMethod();
}
c ' VB
) Interface IAsset
Private j As Integer = 5
Function SampleMethod() as Integer
End Interface

// C#
interface ISampleInterface
{
private int j = 5;
int SampleMethod();
}
d ' VB
) Interface IAsset(j as Integer)
Function SampleMethod() as Integer
End Interface

// C#
interface ISampleInterface(int j)
{
int SampleMethod();
}
ANSWER 3
b) ' VB
Interface IAsset
Function SampleMethod() as Integer
End Interface

// C#
interface ISampleInterface
{
int SampleMethod();
}

For a thorough explanation of the questions and answers shown here, as well as
practice tests and a comprehensive study guide for exam 70-536, order the MCTS Self-
Paced Training Kit (Exam 70-536): Microsoft .NET Framework 2.0—Application
Development Foundation book from Microsoft Press.

Implementing Service Processes, Threading, and Application Domains 
in a .NET Framework Application 
This section contains three practice questions to help prepare you to implement service
processes, threading, and application domains in a .NET Framework application.

• Question 1
• Question 2
• Question 3

Question 1
Which of the following code samples creates an application domain and launches a
process within it?
a ' VB
) Dim d As AppDomain = AppDomain.CreateDomain("Domain", "Assembly")

// C#
AppDomain d = AppDomain.CreateDomain("Domain", "Assembly");
b ' VB
) Dim d As AppDomain = AppDomain.ExecuteAssemblyByName("Domain",
"Assembly")

// C#
AppDomain d = AppDomain.ExecuteAssemblyByName("Domain", "Assembly");
c ' VB
) Dim d As AppDomain = AppDomain.CreateDomain("Domain")
d.ExecuteAssemblyByName("Assembly")

// C#
AppDomain d = AppDomain.CreateDomain("Domain");
d.ExecuteAssemblyByName("Assembly");
d ' VB
) AppDomain.ExecuteAssemblyByName("Assembly")

// C#
AppDomain.ExecuteAssemblyByName("Assembly");
Answer 1
c ' VB
) Dim d As AppDomain = AppDomain.CreateDomain("Domain")
d.ExecuteAssemblyByName("Assembly")

// C#
AppDomain d = AppDomain.CreateDomain("Domain");
d.ExecuteAssemblyByName("Assembly");

Question 2
Which of the following code samples would successfully start the Server service?
a ' VB
) Dim sc As ServiceController = New ServiceController("Server")
sc.Start()

// C#
ServiceController sc = new ServiceController("Server");
sc.Start();
b ' VB
) ServiceController.Start("Server")

// C#
ServiceController.Start("Server");
c ' VB
) Dim sc As ServiceController = New ServiceController()
sc.Start("Server")

// C#
ServiceController sc = new ServiceController();
sc.Start("Server");
d ' VB
) ServiceController.Continue("Server")

// C#
ServiceController.Continue("Server");
Answer 2
a ' VB
) Dim sc As ServiceController = New ServiceController("Server")
sc.Start()

// C#
ServiceController sc = new ServiceController("Server");
sc.Start();

Question 3
You are writing managed code that will be executed within a thread. What do you
need to do to enable your code to recover from a call to Thread.Sleep and a
subsequent Thread.Interrupt call?

a) Respond to the parent process's On_Interrupt event.


b) Implement the IInterruptible interface.
c) Catch the ThreadInterruptedException and do whatever is appropriate to
continue working.
Answer 3
c) Catch the ThreadInterruptedException and do whatever is appropriate to
continue working.

For a thorough explanation of the questions and answers shown here, as well as
practice tests and a comprehensive study guide for exam 70-536, order the MCTS Self-
Paced Training Kit (Exam 70-536): Microsoft .NET Framework 2.0—Application
Development Foundation book from Microsoft Press.

Embedding Configuration, Diagnostic, Management, and Installation 
Features into a .NET Framework Application 
This section contains two practice questions to help prepare you to configure,
diagnose, manage, and install features into a .NET Framework application.

• Question 1
• Question 2

Question 1
You are writing an application that must perform event logging. When is the correct
time to create an event source?

a) Before you write each event.


b) Before you write the first event.
c) During installation.
d) After you restart the computer.
Answer 1
c) During installation

Question 2
As part of a troubleshooting tool for the systems administrators at your organization,
you are writing a command-line tool that automatically kills any unresponsive
applications. Which of the following code samples accomplishes this?
a) ' VB
For Each p As Process In Process.GetProcesses
If Not p.Responding Then
p.Kill
End If
Next

// C#
foreach (Process p in Process.GetProcesses())
if (!p.Responding)
p.Kill();
b) ' VB
For Each p As Process In Process.GetProcesses
If Not p.Responding Then
Process.Kill(p.Id)
End If
Next

// C#
foreach (Process p in Process.GetProcesses())
if (!p.Responding)
Process.Kill(p.Id);
c) ' VB
For Each p As Process In Process.GetUnresponsiveProcesses
p.Kill
Next

// C#
foreach (Process p in Process.GetUnresponsiveProcesses())
p.Kill();
d) ' VB
For Each p As Process In Process.GetUnresponsiveProcesses
Process.Kill(p.Id)
Next
// C#
foreach (Process p in Process.GetUnresponsiveProcesses())
Process.Kill(p.Id);
Answer 2
a) ' VB
For Each p As Process In Process.GetProcesses
If Not p.Responding Then
p.Kill
End If
Next

// C#
foreach (Process p in Process.GetProcesses())
if (!p.Responding)
p.Kill();

For a thorough explanation of the questions and answers shown here, as well as
practice tests and a comprehensive study guide for exam 70-536, order the MCTS Self-
Paced Training Kit (Exam 70-536): Microsoft .NET Framework 2.0—Application
Development Foundation book from Microsoft Press.

Implementing Serialization and Input/Output Functionality in a .NET 
Framework Application 
This section contains five practice questions to help prepare you to implement
serialization and input/output functionality in a .NET Framework application.

• Question 1
• Question 2
• Question 3
• Question 4
• Question 5

Question 1
You are responsible for an internal database application. Your organization would
now like to selectively send information from the database to external customers
using XML documents. Currently, you have custom classes that store this information.
Which class should you use to write the XML documents?

a) BinaryFormatter
b) TextWriter
c) StreamWriter
d) XmlSerializer
Answer 1
d) XmlSerializer

Question 2
You are adding a new member to a class that is already in use. You want to provide
backward compatibility with serialized data that was created before the member
was added. Which attribute would you add to the new member so that it would be
serialized in the future, but de-serialization would not throw an exception if the
member class was not present in the serialized data?

a) ISerializable
b) OptionalField
c) IDeserializationCallback
d) NonSerialized
Answer 2
b) OptionalField

Question 3
Which of the following code samples is the most efficient way to rename a file from
"File1.txt" to "File2.txt"?
a ' VB
) File.Move("File1.txt", "File2.txt")

// C#
File.Move("File1.txt", "File2.txt");
b ' VB
) File.Rename("File1.txt", "File2.txt")

// C#
File.Rename("File1.txt", "File2.txt");
c ' VB
) File.Copy("File1.txt", "File2.txt")
File.Delete("File1.txt")

// C#
File.Copy("File1.txt", "File2.txt");
File.Delete("File1.txt");
d ' VB
)
File.Replace("File1.txt", "File2.txt")

// C#
File.Replace("File1.txt", "File2.txt");
Answer 3
a ' VB
) File.Move("File1.txt", "File2.txt")

// C#
File.Move("File1.txt", "File2.txt");

Question 4
You are working with your IT department to deploy an application that you wrote.
The IT department asks if your application needs access to any folders that are on the
local hard disk. Your application uses only isolated storage. Your application will be
deployed only to new computers that are running Microsoft Windows XP. Your IT
department does not use roaming profiles.

To which folder does your application require access?

a) <systemroot>\Profiles\<user>\Application Data
b) <systemroot>\Application Data
c) <systemdrive>\Documents and Settings\<user>\ Local Settings\Application
Data
d) <systemroot>\Documents and Settings\<user>\Application Data
Answer 4
c) <systemdrive>\Documents and Settings\<user>\ Local Settings\Application
Data

Question 5
Which of the following classes interact with the file system? (Choose all that apply.)

a) FileStream
b) MemoryStream
c) StringReader
d) StreamReader
e) SslStream
Answer 5
a) FileStream
d) StreamReader

For a thorough explanation of the questions and answers shown here, as well as
practice tests and a comprehensive study guide for exam 70-536, order the MCTS Self-
Paced Training Kit (Exam 70-536): Microsoft .NET Framework 2.0—Application
Development Foundation book from Microsoft Press.

Improving the Security of .NET Framework Applications by Using the 
.NET Framework 2.0 Security Features 
This section contains four practice questions to help prepare you to implement the
security of .NET Framework applications by using .NET Framework 2.0 security features.

• Question 1
• Question 2
• Question 3
• Question 4
 

Question 1
You are reviewing a colleague's code for security vulnerabilities. Which of the
following System.Security.Cryptography classes would indicate that the developer
was using weak encryption that could potentially be cracked in a short amount of
time?

a) RijndaeIManaged
b) DES
c) RC2
d) TripleDES
Answer 1
b) DES

Question 2
Your IT department has requested your assistance. They have asked you to write a
console application that analyzes the C:\Boot.ini file to determine whether it is
properly configured. The IT department will deploy your tool with administrative
privileges, and you want to minimize the risk that the application will be abused to
perform another task. Which of the following attributes would you use to minimize the
security risk by limiting the assembly's privileges so that it can access only the
C:\Boot.ini file?

a) ' VB
<Assembly: FileIOPermissionAttribute(SecurityAction.PermitOnly, Read :=
"C:\boot.ini")>
// C#
[assembly:FileIOPermissionAttribute(SecurityAction.PermitOnly,
Read=@"C:\boot.ini")]
b) ' VB
<Assembly: FileIOPermissionAttribute(SecurityAction.RequestMinimum, Read :=
"C:\boot.ini")>

// C#
[assembly:FileIOPermissionAttribute(SecurityAction.RequestMinimum,
Read=@"C:\boot.ini")]
c) ' VB
<Assembly: FileIOPermissionAttribute(SecurityAction.RequestOptional, Read :=
"C:\boot.ini")>

// C#
[assembly:FileIOPermissionAttribute(SecurityAction.RequestOptional,
Read=@"C:\boot.ini")]
d) ' VB
<Assembly: FileIOPermissionAttribute(SecurityAction.RequestMinimum)>

// C#
[assembly:FileIOPermissionAttribute(SecurityAction.RequestMinimum)]
Answer 2
c) ' VB
<Assembly: FileIOPermissionAttribute(SecurityAction.RequestOptional, Read :=
"C:\boot.ini")>

// C#
[assembly:FileIOPermissionAttribute(SecurityAction.RequestOptional,
Read=@"C:\boot.ini")]

Question 3
You are writing an application that stores security log information in a text file. This log
file contains confidential information that only members of the local Administrators
group should be able to view or modify.

Which of the following code samples creates a text file that has the proper
permissions?
a) ' VB
Dim user As NTAccount = New NTAccount("Administrators")
Dim ar As FileSystemAccessRule = New FileSystemAccessRule(user,
FileSystemRights.FullControl, AccessControlType.Allow)
Dim fs As FileSecurity = New FileSecurity
fs.AddAccessRule(ar)
System.IO.File.Create("log.txt", 1000, FileOptions.None, fs)

// C#
NTAccount user = new NTAccount("Administrators");
FileSystemAccessRule ar = new FileSystemAccessRule(user,
FileSystemRights.FullControl, AccessControlType.Allow);
FileSecurity fs = new FileSecurity();
fs.AddAccessRule(ar);
System.IO.File.Create("log.txt", 1000, FileOptions.None, fs);
b) ' VB
Dim user As NTAccount = New NTAccount("Administrator")
Dim ar As FileSystemAccessRule = New FileSystemAccessRule(user,
FileSystemRights.FullControl, AccessControlType.Allow)
Dim fs As FileSecurity = New FileSecurity
fs.AddAccessRule(ar)
System.IO.File.Create("log.txt", 1000, FileOptions.None, fs)

// C#
NTAccount user = new NTAccount("Administrator");
FileSystemAccessRule ar = new FileSystemAccessRule(user,
FileSystemRights.FullControl, AccessControlType.Allow);
FileSecurity fs = new FileSecurity();
fs.AddAccessRule(ar);
System.IO.File.Create("log.txt", 1000, FileOptions.None, fs);
c) ' VB
WindowsIdentity user = WindowsIdentity.GetCurrent()
Dim ar As FileSystemAccessRule = New FileSystemAccessRule(user,
FileSystemRights.FullControl, AccessControlType.Allow)
Dim fs As FileSecurity = New FileSecurity
fs.AddAccessRule(ar)
System.IO.File.Create("log.txt", 1000, FileOptions.None, fs)

// C#
WindowsIdentity user = WindowsIdentity.GetCurrent();
FileSystemAccessRule ar = new FileSystemAccessRule(user,
FileSystemRights.FullControl, AccessControlType.Allow);
FileSecurity fs = new FileSecurity();
fs.AddAccessRule(ar);
System.IO.File.Create("log.txt", 1000, FileOptions.None, fs);
d) ' VB
WindowsIdentity user = WindowsIdentity.GetCurrent()
Dim ar As FileSystemAccessRule = New FileSystemAccessRule(user,
FileSystemRights.FullControl, AccessControlType.Deny)
Dim fs As FileSecurity = New FileSecurity
fs.AddAccessRule(ar)
System.IO.File.Create("log.txt", 1000, FileOptions.None, fs)

// C#
WindowsIdentity user = WindowsIdentity.GetCurrent();
FileSystemAccessRule ar = new FileSystemAccessRule(user,
FileSystemRights.FullControl, AccessControlType.Deny);
FileSecurity fs = new FileSecurity();
fs.AddAccessRule(ar);
System.IO.File.Create("log.txt", 1000, FileOptions.None, fs);
Answer 3
a) ' VB
Dim user As NTAccount = New NTAccount("Administrators")
Dim ar As FileSystemAccessRule = New FileSystemAccessRule(user,
FileSystemRights.FullControl, AccessControlType.Allow)
Dim fs As FileSecurity = New FileSecurity
fs.AddAccessRule(ar)
System.IO.File.Create("log.txt", 1000, FileOptions.None, fs)

// C#
NTAccount user = new NTAccount("Administrators");
FileSystemAccessRule ar = new FileSystemAccessRule(user,
FileSystemRights.FullControl, AccessControlType.Allow);
FileSecurity fs = new FileSecurity();
fs.AddAccessRule(ar);
System.IO.File.Create("log.txt", 1000, FileOptions.None, fs);

Question 4
You are writing an application that connects to a network resource using SslStream.
Which of the following types of exceptions should you catch so that you can retry
authentication with a different set of credentials if authentication fails?

a) FatalAuthenticationException
b) Exception
c) InvalidCredentialException
d) AuthenticationException
Answer 4
d) AuthenticationException

For a thorough explanation of the questions and answers shown here, as well as
practice tests and a comprehensive study guide for exam 70-536, order the MCTS Self-
Paced Training Kit (Exam 70-536): Microsoft .NET Framework 2.0—Application
Development Foundation book from Microsoft Press.

Implementing Interoperability, Reflection, and Mailing Functionality in 
a .NET Framework Application 
This section contains four practice questions to help prepare you to implement
interoperability, reflection, and mailing functionality in a .NET Framework application.

• Question 1
• Question 2
• Question 3
• Question 4

Question 1
You are writing an application that needs to transmit e-mail messages through a
standard SMTP server, and also perform other actions. To ensure administrators
configure the application with the appropriate permissions, you want to declare the
required permission. You do not want to affect the permissions that are granted to
the assembly, however. Which of the following declarations accomplishes this most
effectively?
a) ' VB
<Assembly:SmtpPermission(SecurityAction.RequestOptional,
Access:="Connect")>
// C#
[assembly:SmtpPermission(SecurityAction.RequestOptional, Access="Connect")]
b) ' VB
<Assembly:SmtpPermission(SecurityAction.RequestMinimum,
Access:="Connect")>

// C#
[assembly:SmtpPermission(SecurityAction.RequestMinimum, Access="Connect")]
c) ' VB
<Assembly:SmtpPermission(SecurityAction.RequestMinimum,
Access:="ConnectToUnrestrictedPort")>

// C#
[assembly:SmtpPermission(SecurityAction.RequestMinimum,
Access="ConnectToUnrestrictedPort")]
d) ' VB
<Assembly:SmtpPermission(SecurityAction.RequestOptional,
Access:="ConnectToUnrestrictedPort")>

// C#
[assembly:SmtpPermission(SecurityAction.RequestOptional,
Access="ConnectToUnrestrictedPort")]
Answer 1
b) ' VB
<Assembly:SmtpPermission(SecurityAction.RequestMinimum,
Access:="Connect")>

// C#
[assembly:SmtpPermission(SecurityAction.RequestMinimum, Access="Connect")]

Question 2
As part of your assembly, you must call a COM .dll file. Using Microsoft Visual Studio
2005, what is the easiest way to generate an interop assembly and enable your
assembly to access the dynamic-link library (DLL)?
a) 1. Click the Project menu, and then click Add Reference.
2. Click the COM tab.
3. Select the library in the Available References list, and then click OK.
b) 1. Click the Project menu, and then click Add Reference.
2. Click the .NET tab.
3. Select the library in the Available References list, and then click OK.
c) 1. Click the Project menu, and then click Add Component.
2. Click Browse and select your DLL.
3. Click OK.
d) 1. Using Win32 development tools, create a command-line wrapper for the
COM .dll file.
2. In your .NET Framework assembly, call the command-line wrapper.
Answer 2
a) 1. Click the Project menu, and then click Add Reference.
2. Click the COM tab.
3. Select the library in the Available References list, and then click OK.

Question 3
Which of the following code samples correctly creates a managed definition for an
unmanaged function in the User32.dll file?
a) ' VB
Imports System.Runtime.InteropServices
Public Class Win32
<DllDeclare ("user32.dll", CharSet := CharSet.Auto)>_
Public Shared Function MessageBox (ByVal hWnd As Integer, _
ByVal txt As String, ByVal caption As String, _
ByVal Typ As Integer) As IntPtr
End Function
End Class

// C#
using System.Runtime.InteropServices;
[DllDeclare("user32.dll")]
public static extern IntPtr MessageBox(int hWnd, String text,
String caption, uint type);
b) ' VB
Imports System.Runtime.InteropServices
Public Class Win32
<DllImport ("user32.dll", CharSet := CharSet.Auto)>_
Public Shared Function MessageBox (ByVal hWnd As Integer, _
ByVal txt As String, ByVal caption As String, _
ByVal Typ As Integer) As IntPtr
End Function
End Class

// C#
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern IntPtr MessageBox(int hWnd, String text,
String caption, uint type);
c) ' VB
Imports System.Runtime.InteropServices
Public Class Win32
<DllImport ("user32.dll", CharSet := CharSet.Auto)>_
Declare Public Shared Function MessageBox (ByVal hWnd As Integer, _
ByVal txt As String, ByVal caption As String, _
ByVal Typ As Integer) As IntPtr
End Function
End Class

// C#
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
declare public static extern IntPtr MessageBox(int hWnd, String text,
String caption, uint type);
d) ' VB
Imports System.Runtime.InteropServices
Public Class Win32
<DllDeclare ("user32.dll", CharSet := CharSet.Auto)>_
Declare Public Shared Function MessageBox (ByVal hWnd As Integer, _
ByVal txt As String, ByVal caption As String, _
ByVal Typ As Integer) As IntPtr
End Function
End Class

// C#
using System.Runtime.InteropServices;
[DllDeclare("user32.dll")]
declare public static extern IntPtr MessageBox(int hWnd, String text,
String caption, uint type);
Answer 3
b) ' VB
Imports System.Runtime.InteropServices
Public Class Win32
<DllImport ("user32.dll", CharSet := CharSet.Auto)>_
Public Shared Function MessageBox (ByVal hWnd As Integer, _
ByVal txt As String, ByVal caption As String, _
ByVal Typ As Integer) As IntPtr
End Function
End Class

// C#
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern IntPtr MessageBox(int hWnd, String text,
String caption, uint type);

Question 4
Within your .NET Framework version 2.0 assembly, you need to load a .NET Framework
version 1.1 assembly to examine its metadata given its file name. Which method
should you use?

a) Assembly.LoadModule
b) Assembly.ReflectionOnlyLoadFrom
c) Assembly.ReflectionOnlyLoad
d) Assembly.LoadFile
Answer 4
b) Assembly.ReflectionOnlyLoadFrom

For a thorough explanation of the questions and answers shown here, as well as
practice tests and a comprehensive study guide for exam 70-536, order the MCTS Self-
Paced Training Kit (Exam 70-536): Microsoft .NET Framework 2.0—Application
Development Foundation book from Microsoft Press.
Implementing Globalization, Drawing, and Text Manipulation 
Functionality in a .NET Framework Application 
This section contains three practice questions to help prepare you to implement
globalization, drawing, and text manipulation functionality in a .NET Framework
application.

• Question 1
• Question 2
• Question 3

Question 1
Which of the following code samples draws a line from the upper-left corner toward
the lower-right corner?
a) ' VB
Dim g As Graphics = Me.CreateGraphics
Dim p As Pen = New Pen(Color.Red, 7)
g.DrawLine(p, 1, 1, 100, 100)

// C#
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Red, 7);
g.DrawLine(p, 1, 1, 100, 100);
b) ' VB
Dim g As Graphics = Me.CreateGraphics
Dim b As Brush = New Brush(Color.Red, 7)
g.DrawLine(b, 1, 1, 100, 100)

// C#
Graphics g = this.CreateGraphics();
Brush b = new Brush(Color.Red, 7);
g.DrawLine(b, 1, 1, 100, 100);
c) ' VB
Dim g As Graphics = Me.CreateGraphics
Dim p As Pen = New Pen(Color.Red, 7)
g.DrawLine(p, 100, 1, 1, 100)

// C#
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Red, 7);
g.DrawLine(p, 100, 1, 1, 100);
d) ' VB
Dim g As Graphics = Me.CreateGraphics
Dim b As Brush = New Brush(Color.Red, 7)
g.DrawLine(b, 100, 1, 1, 100)

// C#
Graphics g = this.CreateGraphics();
Brush b = new Brush(Color.Red, 7);
g.DrawLine(b, 100, 1, 1, 100);
Answer 1
a) ' VB
Dim g As Graphics = Me.CreateGraphics
Dim p As Pen = New Pen(Color.Red, 7)
g.DrawLine(p, 1, 1, 100, 100)

// C#
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Red, 7);
g.DrawLine(p, 1, 1, 100, 100);

Question 2
Which of the following code samples is the most efficient and compiles correctly?
a) ' VB
Dim s As String = Nothing
Dim sb As StringBuilder = Nothing
sb = "Hello"
sb += ", "
sb += "World"
sb += "!"
s = sb.ToString

// C#
string s = null;
StringBuilder sb = null;
sb = "Hello";
sb += ", ";
sb += "World";
sb += "!";
s = sb.ToString();
b) ' VB
Dim s As String = Nothing
Dim sb As StringBuilder = Nothing
sb.Append("Hello")
sb.Append(", ")
sb.Append("World")
sb.Append("!")
s = sb.ToString

// C#
string s = null;
StringBuilder sb = null;
sb.Append("Hello");
sb.Append(", ");
sb.Append("World");
sb.Append("!");
s = sb.ToString();
c) ' VB
Dim s As String = Nothing
s = "Hello"
s += ", "
s += "World"
s += "!"

// C#
string s = null;
s = "Hello";
s += ", ";
s += "World";
s += "!";
d) ' VB
Dim s As String = Nothing
s = "Hello"
s = s + ", "
s = s + "World"
s = s + "!"

// C#
string s = null;
s = "Hello";
s += ", ";
s += "World";
s += "!";
Answer 2
b) ' VB
Dim s As String = Nothing
Dim sb As StringBuilder = Nothing
sb.Append("Hello")
sb.Append(", ")
sb.Append("World")
sb.Append("!")
s = sb.ToString

// C#
string s = null;
StringBuilder sb = null;
sb.Append("Hello");
sb.Append(", ");
sb.Append("World");
sb.Append("!");
s = sb.ToString();

Question 3
You are writing an English-language client application that must process data files
that are generated by a server application. The server application runs at your
organization's office in Sweden and was developed locally. How can you change
the culture of your application to ensure that the data file is processed correctly?
a) ' VB
CultureInfo.CurrentCulture = "sv-SE"

// C#
CultureInfo.CurrentCulture = "sv-SE";
b) ' VB
Thread.CurrentThread.CurrentCulture = New CultureInfo("sv-SE")

// C#
Thread.CurrentThread.CurrentCulture = new CultureInfo("sv-SE");
c) ' VB
CultureInfo.CurrentCulture = New CultureInfo("sv-SE")

// C#
CultureInfo.CurrentCulture = new CultureInfo("sv-SE");
d) ' VB
Thread.CurrentThread.CurrentCulture.Name = "sv-SE"

// C#
Thread.CurrentThread.CurrentCulture.Name = "sv-SE";
Answer 3
b) ' VB
Thread.CurrentThread.CurrentCulture = New CultureInfo("sv-SE")

// C#
Thread.CurrentThread.CurrentCulture = new CultureInfo("sv-SE");

For a thorough explanation of the questions and answers shown here, as well as
practice tests and a comprehensive study guide for exam 70-536, order the MCTS Self-
Paced Training Kit (Exam 70-536): Microsoft .NET Framework 2.0—Application
Development Foundation book from Microsoft Press.

You might also like