Learn About Upgrade: MCAD Skills to MCTS Windows Applications

These questions are based on 70-553VB: Upgrade: MCAD Skills to MCTS Windows Applications by Using the Microsoft .NET Framework (VB.NET)

A Self Test Software Practice Test

Objective: Develop applications that use system types and collections.
Sub-objective: Manage a group of associated data in a .NET Framework application by using collections (Refer System.Collections namespace).

Single answer, multiple-choice

You are an application developer for your company. You are creating an application that uses a Queue class object named MyQueue to store messages sent by the user during application run time.

Before processing the user messages, you want to access the message at the beginning of the queue without removing it. Which method of the MyQueue object should you use?

A.    Peek.
B.    Dequeue.
C.    Enqueue.
D.    Contains.

Answer:
A

Tutorial:
You should use the Peek method to access the message that is stored at the beginning of the MyQueue object. The Peek method accesses the element stored at the beginning of the object of the Queue class without removing the element from the queue. The Queue class is a data structure for handling elements based on the First In First Out (FIFO) concept. According to the FIFO concept, elements that are stored first are processed first.

You should not use the Dequeue method of the Queue class because this method is used to remove the next element at the beginning of a Queue object. In this scenario, you want to access the next element at the beginning of the MyQueue object without removing it.

You should not use the Enqueue method of the Queue class because this method is used to add a new element to the end of a Queue object. In this scenario, you want to access the element stored at the beginning of the MyQueue object without removing it.

You should not use the Contains method of the Queue class because this method is used to verify whether the specified element exists for the Queue object instance or not. In this scenario, you want to access the message stored at the beginning of the MyQueue object without removing it.

Reference:

MSDN2 Library > .NET Development > .NET Framework SDK > Class Library Reference > System.Collections > Queue Class > Queue Members

Objective: Implement serialization and input/output functionality in a .NET Framework application.
Sub-objective: Access files and folders by using the File System classes (Refer System.IO namespace).

Single answer, multiple-choice

You are an application developer for a company. You are creating a file management application to monitor the hosts file. You want to replace the hosts file if it has been changed. You need to display the size and whether the hosts file is set to read-only. Which code should you use?

A.    Dim hosts As New _
  File ("C:Windowssystem32driversetchosts")
Console.WriteLine("ReadOnly? " & hosts.IsReadOnly)
Console.WriteLine("Size: " & hosts.Length)
B.    Dim hosts As New _
  File ("C:Windowssystem32driversetchosts")
Console.WriteLine("ReadOnly? " & hosts.GetReadOnly())
Console.WriteLine("Size: " & hosts.GetLength())
C.    Dim hosts As New _
  FileInfo("C:Windowssystem32driversetchosts")
Console.WriteLine("ReadOnly? " & hosts.IsReadOnly)
Console.WriteLine("Size: " & hosts.Length)
D.    Dim hosts As New _
  FileInfo("C:Windowssystem32driversetchosts")
Console.WriteLine("ReadOnly? " & hosts.IsReadOnly)
Console.WriteLine("Size: " & hosts.Size)

Answer:
C

Tutorial:
You should use the following code to display the size and whether the hosts file is set to read-only:

Dim hosts As New _
  FileInfo("C:Windowssystem32driversetchosts")
Console.WriteLine("ReadOnly? " & hosts.IsReadOnly)
Console.WriteLine("Size: " & hosts.Length)

This code instantiates a FileInfo object using a file path string and outputs the IsReadOnly and Length properties to the command line. The FileInfo object represents information about a system file. Whereas the File class contains only methods, the FileInfo class contains common properties and methods for reading and setting file metadata and contents. The IsReadOnly property returns a Boolean value indicating whether the file is set to read-only. The Length property returns the size of the file in bytes.

You should not use the code fragments that use the File class because the File class does not contain an IsReadOnly or Length property. Though the File class and FileInfo classes overlap in many ways, the FileInfo class offers properties the File class does not directly provide. This is the case with the IsReadOnly and Length property. You should use the FileInfo class in this scenario.

You should not use the code fragments that specify the GetReadOnly and GetLength methods or the Size property because no such methods or property exists.

Reference:

MSDN2 Library > .NET Development > .NET Framework SDK > Class Library Reference > System.IO > FileInfo Class > FileInfo Members

Objective: Improvie the security of .NET Framework applications by using the .NET Framework 2.0 security features.
Sub-objective: Access and modify identity information by using the System.Security.Principal classes (Refer System.Security.Principal namespace).

Single answer, multiple-choice

You are an application developer for a company. You are creating an application for displaying confidential employee information. This information should be available for viewing only by managers and administrators. You use Windows authentication and .NET role-based security to ensure this.

Your network administrator detects that certain users who are not managers or administrators are able to view the employee information. After examining your code, you determine an issue with domain group memberships.

You need to trace the user account and security identifier (SID) of each user in your application. The network administrator can use this information to detect users across the enterprise and verify their group memberships are correct. Which code should you use to trace the user account and SID of each user?

A.    Dim curID As WindowsIdentity = WindowsIdentity.GetCurrent()
Dim sid As New SecurityIdentifier(curID.Name)
Trace.Write("User's SID is " & sid.Value, "User " & sid.Name)
B.    Dim curID As WindowsIdentity = WindowsIdentity.GetCurrent()
Trace.Write("User's SID is " & curID.SID, "User " & curID.Name)
C.    Dim curID As WindowsIdentity = WindowsIdentity.GetCurrent()
Dim account As New NTAccount(curID.Name)
Dim sid As SecurityIdentifier = _
   CType(account.Translate( _
  GetType(SecurityIdentifier)), SecurityIdentifier)
Trace.Write("User's SID is " & sid.Value, "User " & account.Value)
D.    Dim curID As WindowsIdentity = WindowsIdentity.GetCurrent()
Dim account As New NTAccount(curID.Name)
Trace.Write("User's SID is " & account.SID, "User " & account.Name)

Answer:
C

Tutorial:
You should use the following code to trace the user account and SID of the current user:

Dim curID As WindowsIdentity = WindowsIdentity.GetCurrent()
Dim account As New NTAccount(curID.Name)
Dim sid As SecurityIdentifier = _
   CType(account.Translate( _
  GetType(SecurityIdentifier)), SecurityIdentifier)
Trace.Write("User's SID is " & sid.Value, "User " & account.Value)

This code retrieves the current WindowsIdentity object associated with the user, instantiates an NTAccount object using the Name property, invokes the Translate method to retrieve the current SecurityIdentifier object and invokes the Write method on the Trace class to record the Value property of both the SecurityIdentifier and NTAccount objects. The GetCurrent method of the WindowsIdentity class returns a WindowsIdentity object representing the identity of the application user.

The NTAccount class represents a Windows user or group account in the local Security Accounts Manager (SAM) or in the Active Directory domain. The constructor of the NTAccount class accepts either a single string representing the account name or two strings, one representing the domain name and the other representing the account on that domain. To facilitate SID lookups, the Translate method takes a Type argument and returns an IdentityReference object.

You must convert or cast the IdentityReference object to a SecurityIdentifier object to retrieve the SID for the specified account. The Value property of the SecurityIdentifier and NTAccount class returns a SID and fully qualified user name string, respectively. The Write method of the Trace class outputs the specified message into the specified category. In this case, the output of the Trace will resemble the following:

User CompanyWGates:
     User's SID is S-1-5-30-4268806841-974645416-195214038-23611

You should not use the code that does not specify the NTAccount class because a SecurityIdentifier object cannot be instantiated using an account name as an argument, and it does not contain a Name property. You should use the Translate method of the NTAccount class to retrieve the SID associated with a user account.

You should not use the code that does not specify the NTAccount and SecurityIdentifier classes because there is no SID property in the WindowsIdentity class. You should use the NTAccount and SecurityIdentifier classes to retrieve the SID of the current user account.

You should not use the code that does not specify the SecurityIdentifier class because the NTAccount class does not have a SID property. You should invoke the Translate method of the NTAccount class to retrieve the SID of the current user account.

Reference:

MSDN2 Library > .NET Development > .NET Framework SDK > Class Library Reference > System.Security.Principal > NTAccount Class

Objective: Create a UI for a Windows Forms Application by using standard controls.
Sub-objective: Add and configure a Windows Forms control.

Single answer, multiple-choice

You have created a Windows application for your organization. The application minimizes to an icon in the system tray when you click the Minimize button of the Windows form. You want to create a pop-up menu to appear when the user right-clicks the icon in the notification area.

The Exit item on the pop-up menu is assigned to allow the user to close the program. Which property of the NotifyIcon component should you use to implement the required functionality in your application?

A.    ContextMenu.
B.    Tag.
C.    BalloonTipText.
D.    BalloonTipTitle.

Answer:
A

Tutorial:
You should use the ContextMenu property of the NotifyIcon component. This property is used to set the shortcut menu for the icon. When the user right-clicks the icon in the notification area of the taskbar, a shortcut menu — which is also known as the pop-up menu — appears.

You should not use the Tag property. The Tag property is used to set the data about the NotifyIcon component itself. For instance, you might have a TextBox where you want to revert to the original value if a user decides to cancel edits. You could store the original value in the Tag property and pull that out when needed if you're not using data binding. In this scenario, you have used a pop-up menu instead of a balloon tip associated with the icon in the notification area. Therefore, you should not use this property in this scenario.

You should not use the BalloonTipText property. This property is used to specify the text to be displayed on the balloon tip associated with the NotifyIcon control (e.g., on MouseHover). In this scenario, you have used a pop-up menu instead of a balloon tip associated with the icon in the notification area. Therefore, you should not use this property in this scenario.

You should not use the BalloonTipTitle property. This property specifies the title of the balloon tip associated with the NotifyIcon control. In this scenario, you are not dealing with a balloon tip in the current application. Therefore, this property will not be valid in this scenario.

Reference:

MSDN Library > Development Tools and Languages > Visual Studio > Windows-based Applications, Components, and Services > Creating Windows-based Applications > Windows Forms > Getting Started with Windows Forms > Windows Forms Controls > Controls to Use on Windows Forms > NotifyIcon Component Overview

Objective: Integrate data in a Windows Forms Application.
Sub-objective: Manage connections and transactions.

Single answer, multiple-choice

You are an application developer for your company. You are creating a Windows application that will be used by your employees to manage a SQL Server database Sales.

The Sales database is stored on a Microsoft SQL Server 2005 instance named SqlServer1. As per your database administrator's recommendation to manage SqlServer1 instance performance, the maximum number of connections to the SqlServer1 instance should be 100.

You decide to establish a connection with the Sales database and implement connection pooling. Which code should you use to establish the connection with the Sales database?

A.    Dim con As New System.Data.SqlClient.SqlConnection
con.ConnectionString = "Data Source=SqlServer1;" & _
     "Integrated Security=true;Initial Catalog=Sales;" & _
     "Pooling=true;Max Pool Size=100;Min Pool Size=1;"
con.Open()
B.    Dim con As New System.Data.SqlClient.SqlConnection
con.ConnectionString = "Data Source=SqlServer1;" & _
     "Integrated Security=true;Initial Catalog=Sales;" & _
     "Pooling=true;"
con.Open()
C.    Dim con As New System.Data.SqlClient.SqlConnection
con.ConnectionString = "Data Source=SqlServer1;" & _
     "Integrated Security=true;Initial Catalog=Sales;" & _
     "Pooling=true;Max Pool Size=100;Min Pool Size=0"
con.Open()
D.    Dim con As New System.Data.SqlClient.SqlConnection
con.ConnectionString = "Data Source=SqlServer1;" & _
     "Integrated Security=true;Initial Catalog=Sales;" & _
     "Pooling=true;Max Pool Size=1;Min Pool Size=100;"
con.Open()

Answer:
A

Tutorial:
You should use the following code:

Dim con As New System.Data.SqlClient.SqlConnection
con.ConnectionString = "Data Source=SqlServer1;" & _
     "Integrated Security=true;Initial Catalog=Sales;" & _
     "Pooling=true;Max Pool Size=100;Min Pool Size=1;"
con.Open()

This code uses the SqlConnection class to establish a connection with the SQL Server 2005 database named Sales. This code first creates the con object and then sets the ConnectionString property of the con object. The ConnectionString property contains parameters, such as Data Source, User ID, Integrated Security, Password, Initial Catalog, Pooling, Max Pool Size and Min Pool Size. The Data Source parameter specifies the name of the computer on which the database is stored. In this scenario, the SQL Server instance name is SqlServer1; therefore, this code sets the Data Source parameter to SqlServer1.

The User ID parameter specifies the user name to be used. The Password parameter specifies the password of the user specified in the User ID parameter. The Integrated Security parameter is used to specify whether Windows authentication is used or not to establish the connection. The Initial Catalog parameter is used to specify the name of the database that will be accessed by using the SqlConnection object.

In this scenario, you will be using the Sales database. Therefore, this code sets the Initial Catalog parameter to Sales. The Pooling parameter specifies whether connection pooling for the SqlConnection object is enabled or not. The Max Pool Size parameter specifies the maximum number of connections that can be pooled in the connection pool. Your application will discard any requests to establish a connection if the maximum pool size value of a connection pool is reached. In this scenario, you must ensure that the maximum number of connections to the SqlServer1 instance is 100. Therefore, this code sets the Max Pool Size parameter to 100.

The Min Pool Size parameter specifies the minimum number of inactive connections that will be available in the pool at any point in time. If the Min Pool Size parameter contains a value greater than zero, the connection pool is not destroyed until the application is running. This code also uses the Open method of the SqlConnection class. The Open method attempts to establish a connection with the specified SQL Server by using the ConnectionString property parameters.

You should not use the code that does not specify the Max Pool Size and Min Pool Size parameters in the connection string. In this scenario, you must ensure that the maximum number of connections to the SqlServer1 instance is 100. Therefore, you should set the Max Pool Size and Min Pool Size parameters.

You should not use the code that specifies a Min Pool Size parameter value of 0 in the connection string. The Min Pool Size parameter specifies the minimum number of inactive connections that will be available in the pool at any point in time. If the Min Pool Size parameter contains a value greater than zero, the connection pool is not destroyed until the application is running.

You should not use the code that sets the Max Pool Size parameter to 1 and the Min Pool Size parameter to 100 because these values are reversed. In this scenario, you must ensure that the maximum number of connections to the SqlServer1 instance is 100. Therefore, you should set the Max Pool Size parameter value to 100 and the Min Pool Size parameter value to 1.

Reference:

MSDN Library > .NET Development > .NET Framework SDK > Class Library Reference > System.Data.SqlClient > SqlConnection Class > SqlConnection Properties > ConnectionString Property

Like what you see? Share it.Google+LinkedInFacebookRedditTwitterEmail
cmadmin

ABOUT THE AUTHOR

Posted in Archive|

Comment: