Tuesday

MICROSOFT .NET FRAMEWORK 2013 EXAM QUESTIONS

                            PART 3 OF 10(WITH EXPLANATION)


QUESTION 1

You need to write a code segment that transfers the contents of a byte array named dataToSend by using a
NetworkStream object named netStream. You need to use a cache of size 8,192 bytes.

Which code segment should you use?

A. MemoryStream memStream = new MemoryStream(8192);
memStream.Write(dataToSend, 0, (int) netStream.Length);
B. MemoryStream memStream = new MemoryStream(8192);
netStream.Write(dataToSend, 0, (int) memStream.Length);
C. BufferedStream bufStream = new BufferedStream(netStream, 8192);
bufStream.Write(dataToSend, 0, dataToSend.Length);
D. BufferedStream bufStream = new BufferedStream(netStream);
bufStream.Write(dataToSend, 0, 8192);

Correct Answer: C

Explanation: To send data using a cache it is necessary to use a BufferedStream. The BufferedStream should be created with the cache size of 8192 bytes.


QUESTION 2

You are developing a method that searches a string for a substring. The method will be localized to Italy.
Your method accepts the following parameters:
· The string to be searched, which is named searchList
· The string for which to search, which is named searchValue.
You need to write the code. Which code segment should you use?

A. return searchList.IndexOf(searchValue);

B. CompareInfo comparer = new CultureInfo("it-IT").CompareInfo; return comparer.Compare(searchList, searchValue);

C. CultureInfo Comparer = new CultureInfo("it-IT");
if (searchList.IndexOf(searchValue) > 0)
{
return true;
}
else
{
return false;
}

D. CompareInfo comparer = new CultureInfo("it-IT").CompareInfo;
if (comparer.IndexOf(searchList, searchValue) > 0)
{
return true;
}
else
{
return false;
}

Correct Answer: D

QUESTION 3

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 outStream = new MemoryStream();
GZipStream zipStream = new GZipStream(outStream, CompressionMode.Compress);
zipStream.Write(document, 0, document.Length);
zipStream.Close();
return outStream.ToArray();

B. MemoryStream inStream = new MemoryStream(document);
GZipStream zipStream = new GZipStream(inStream, CompressionMode.Compress);
byte[] result = new byte[document.Length];
zipStream.Write(result, 0, result.Length);
return result;

C. MemoryStream stream = new MemoryStream(document);
GZipStream zipStream = new GZipStream(stream, CompressionMode.Compress);
zipStream.Write(document, 0, document.Length);
zipStream.Close();
return stream.ToArray();

D. MemoryStream inStream = new MemoryStream(document);
GZipStream zipStream = new GZipStream(inStream, CompressionMode.Compress);
MemoryStream outStream = new MemoryStream();
int b;
while ((b = zipStream.ReadByte()) != -1) {
outStream.WriteByte((byte)b);
}
return outStream.ToArray();

Correct Answer: A

QUESTION 4

You write the following code to call a function from the Win32 Application Programming Interface (API) by using platform invoke.
int rc = MessageBox(hWnd, text, caption, type);
You need to define a method prototype. Which code segment should you use?

A. [DllImport("user32")]
public static extern int MessageBox(int hWnd, String text,String caption, uint type);

B. [DllImport("user32")]
public static extern int MessageBoxA(int hWnd, String text,String caption, uint type);

C. [DllImport("user32")]
public static extern int Win32API_User32_MessageBox(int hWnd, String text, String caption, uint type);

D. [DllImport(@"C:\WINDOWS\system32\user32.dll")]
public static extern int MessageBox(int hWnd, String text,String caption, uint type);

Correct Answer: A

Explanation: Mark the prototype with the Dllimport attribute specifying the library\dll that the function resides in.

QUESTION 5

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 class Role : ConfigurationElement
{i
nternal string ElementName = "name";
[ConfigurationProperty("role")]
public string Name
{
get { return ((string)base["role"]); }
}}

B. public class Role : ConfigurationElement
{i
nternal string ElementName = "role";
[ConfigurationProperty("name", RequiredValue = true)]
public string Name
{
get { return ((string)base["name"]); }
}}

C. public class Role : ConfigurationElement
{i
nternal string ElementName = "role";
private String name;
[ConfigurationProperty("name")]
public string Name
{
get { return name; }
}}

D. public class Role : ConfigurationElement
{i
nternal string ElementName = "name";
private String name;
[ConfigurationProperty("role", RequiredValue = true)]
public string Name
{
get { return name; }
}}

Correct Answer: B

QUESTION 6

You are using the Microsoft Visual Studio 2005 IDE to examine the output of a method that returns a string.
You assign the output of the method to a string variable named fName. You need to write a code segment that prints the following on a single line:
The message: "Test Failed: " The value of fName if the value of fName does not equal "Company" You also need to ensure that the code segment simultaneously facilitates uninterrupted execution of the application. Which code segment should you use?

A. Debug.Assert(fName == "Company", "Test Failed: ", fName);

B. Debug.WriteLineIf(fName != "Company", fName, "Test Failed");

C. if (fName != "Company")
{
Debug.Print("Test Failed: ");
Debug.Print(fName);
}

D. if (fName != "Company")
{
Debug.WriteLine("Test Failed: ");
Debug.WriteLine(fName);
}

Correct Answer: B

QUESTION 7

You are developing an application that will use custom authentication and role-based security. You need to write a code segment to make the runtime assign an unauthenticated principal object to each running thread.
Which code segment should you use?

A. AppDomain domain = AppDomain.CurrentDomain;
domain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

B. AppDomain domain = AppDomain.CurrentDomain;
domain.SetThreadPrincipal(newWindowsPrincipal(null));

C. AppDomain domain = AppDomain.CurrentDomain;
domain.SetAppDomainPolicy(PolicyLevel.CreateAppDomainLevel());

D. AppDomain domain = AppDomain.CurrentDomain;
domain.SetPrincipalPolicy(PrincipalPolicy.UnauthenticatedPrincipal);

Correct Answer: D

Explanation: Setting the PrincipalPolicy for the AppDomain to UnauthenticatedPrincipal will
default the Principal for each thread to an unauthenticated principal .
QUESTION 8

You write a class named Employee that includes the following code segment.
public class Employee
{
string employeeId,
string employeeName,
string jobTitleName;
public string GetName() { return employeeName; }
public string GetTitle() { return jobTitleName; }
}
You need to expose this class to COM in a type library. The COM interface must also facilitate forwardcompatibility 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
{

Correct Answer: D

QUESTION 9

You need to write a multicast delegate that accepts a DateTime argument and returns a Boolean value. Which code segment should you use?

A. public delegate int PowerDeviceOn(bool,DateTime);
B. public delegate bool PowerDeviceOn(Object,EventArgs);
C. public delegate void PowerDeviceOn(DateTime);
D. public delegate bool PowerDeviceOn(DateTime);

Correct Answer: A

QUESTION 10

You need to select a class that is optimized for key-based item retrieval from both small and large collections.
Which class should you choose?

A. OrderedDictionary class
B. HybridDictionary class
C. ListDictionary class
D. Hashtable class

Correct Answer: B

Explanation: A HybridDictionary is implemented as a ListDictionary for small collections and a Hashtable for
large collections. Hence it provides very efficient storage for both small and large collections.

OrderedDictionary supports sorting based on the key. It has similar disadvantages for small collections to Hashtable on which it is based.
ListDictionary is ideal for small collections because it is implemented as a light-weight linked list.
Performance will suffer for large collections.
HashTable is ideal for large collections, for small collections the overheads of such a sophisticated data structure do not compensate for the benefits.

CLICK FOR PART 4 OF 10
CLICK FOR PART 1 OF 10

No comments:

Post a Comment