Exam 70-505:
TS: Microsoft .NET Framework 3.5, Windows Forms Application Development
Published: February 05, 2009
Language(s): English, French, German, Japanese, Spanish, Chinese (Simplified)
Audience(s): Developers
Technology: Microsoft Visual Studio 2008
Type: Proctored Exam
QUESTION NO: 1
You are creating a Windows application by using the .NET Framework 3.5. You plan to create a form that might result in a time-consuming operation. You use the QueueUserWorkItem method and a Label control named lblResult. You need to update the users by using the lblResult control when the process has completed the operation. Which code segment should you use?
A. Private Sub DoWork(ByVal myParameter As Object) ‘thread work Invoke(New MethodInvoker(AddressOf ReportProgress))End SubPrivate Sub ReportProgress () Me.lblResult.Text = “Finished Thread”End Sub
B. Private Sub DoWork (ByVal myParameter As Object) ‘thread work Me.lblResult.Text = “Finished Thread”End Sub
C. Private Sub DoWork (ByVal myParameter As Object)’thread work System.Threading.Monitor.Enter(Me) Me.lblResult.Text = “Finished Thread” System.Threading.Monitor.Exit(Me)End Sub
D. Private Sub DoWork (ByVal myParameter As Object) ‘thread work System.Threading.Monitor.TryEnter(Me) ReportProgress()End SubPrivate Sub ReportProgress () Me.lblResult.Text = “Finished Thread”End Sub
Answer: A
QUESTION NO: 2
You are creating a Windows component by using the .NET Framework 3.5. The component will be used in Microsoft Word 2007 by using a ribbon button. The component uploads large files to a network file share. You find that Word 2007 becomes non-responsive during the upload. You plan to create your own thread to execute the upload. You need to ensure that the application completes the upload efficiently. What should you do?
A. Use the AsyncResult.SyncProcessMessage method.
B. Call the BeginInvoke method, perform the upload, and then call the EndInvoke method.
C. Retrieve a WaitHandle from an implementation of the IAsyncResult interface before the upload.
D. Set the IsCompleted property on an implementation of the IAsyncResult interface before the upload.
Answer: B
QUESTION NO: 3
You are creating a Windows Forms application by using the .NET Framework 3.5. The application requires a thread that accepts a single integer parameter. You write the following code segment. (Line numbers are included for reference only.) 01 Dim myThread As Thread = New Thread(New _ ParameterizedThreadStart(AddressOf DoWork))02 myThread.Start(100)03 You need to declare the method signature of the DoWork method. Which method signature should you use?
A. Public Sub DoWork()
B. Public Sub DoWork(ByVal nCounter As Integer)
C. Public Sub DoWork(ByVal oCounter As Object)
D. Public Sub DoWork(ByVal oCounter As System.Delegate)
Answer: C
QUESTION NO: 4
You are creating a Windows application by using the .NET Framework 3.5. The Windows application has the print functionality. You create an instance of a BackgroundWorker component named backgroundWorker1 to process operations that take a long time. You discover that when the application attempts to report the progress, you receive a System.InvalidOperationException exception when executing the backgroundWorker1.ReportProgress method. You need to configure the BackgroundWorker component appropriately to prevent the application from generating exceptions. What should you do?
A. Set the Result property of the DoWorkEventArgs instance to True before you attempt to report the progress.
B. Set the CancellationPending property of backgroundWorker1 to True before you attempt to report the background process.
C. Set the WorkerReportsProgress property of backgroundWorker1 to True before you attempt to report the background process.
D. Report the progress of the background process in the backgroundWorker1_ProgressChanged event.
Answer: C
QUESTION NO: 5
You are creating a Windows application for graphical image processing by using the .NET Framework 3.5. You create an image processing function and a delegate. You plan to invoke the image processing function by using the delegate. You need to ensure that the calling thread meets the following requirements: It is not blocked when the delegate is running.It is notified when the delegate is complete. What should you do?
A. Call the Invoke method of the delegate.
B. Call the BeginInvoke and EndInvoke methods of the delegate in the calling thread.
C. Call the BeginInvoke method by specifying a callback method to be executed when the delegate is complete. Call the EndInvoke method in the callback method.
D. Call the BeginInvoke method by specifying a callback method to be executed when the delegate is complete. Call the EndInvoke method of the delegate in the calling thread.
Answer: C
QUESTION NO: 6
You are creating a Windows application by using the .NET Framework 3.5. The Windows application has print functionality. You create an instance of a BackgroundWorker component named backgroundWorker1. You discover that when the application attempts to cancel the background process, you receive a System.InvalidOperationException exception on the following code segment: backgroundWorker1.CancelAsync() You need to configure the BackgroundWorker component appropriately to prevent the application from generating exceptions. What should you do?
A. Cancel the background process in the backgroundWorker1_DoWork event.
B. Set the IsBusy property of backgroundWorker1 to True before you attempt to cancel the progress.
C. Set the WorkerSupportsCancellation property of backgroundWorker1 to True before you attempt to cancel the progress.
D. Set the DoWorkEventArgs Cancel property to True in the backgroundWorker1_DoWork event handler before you attempt to cancel the background process.
Answer: C
QUESTION NO: 7
You are creating a Windows Forms application by using the .NET Framework 3.5. You write the following code segment to bind a list of categories to a drop-down list. (Line numbers are included for reference only.) 01 Dim cnnNorthwind As OleDbConnection = _ New OleDbConnection(connectionString)02 Dim cmdCategory As OleDbCommand = New OleDbCommand( _ “SELECT CategoryID, CategoryName FROM Categories ORDER BY CategoryName”, cnnNorthwind)03 Dim daCategory As OleDbDataAdapter = _ New OleDbDataAdapter(cmdCategory)04 Dim dsCategory As DataSet = New DataSet()05 daCategory.Fill(dsCategory)06 You need to ensure that the drop-down list meets the following requirements: Displays all category names.Uses the category ID as the selected item value. Which code segment should you add at line 06?
A. ddlCategory.DataSource = dsCategoryddlCategory.DisplayMember = “CategoryName”ddlCategory.ValueMember = “CategoryID”
B. ddlCategory.DataSource = dsCategory.Tables(0)ddlCategory.DisplayMember = “CategoryName”ddlCategory.ValueMember = “CategoryID”
C. ddlCategory.DataBindings.Add(”DisplayMember”, _ dsCategory, “CategoryName”)ddlCategory.DataBindings.Add(”ValueMember”, _ dsCategory, “CategoryID”)
D. ddlCategory.DataBindings.Add(”DisplayMember”, _ dsCategory.Tables(0), “CategoryName”)ddlCategory.DataBindings.Add(”ValueMember”, _ dsCategory.Tables(0), “CategoryID”)
Answer: B
QUESTION NO: 8
You are creating a Windows Forms application by using the .NET Framework 3.5. The application stores a list of part numbers in an integer-based array as shown in the following code segment. (Line numbers are included for reference only.) 01 Dim parts() As Integer = _ {105, 110, 110, 235, 105, _ 135, 137, 205, 105, 100, 100}02 03 For Each item In results04 tbResults.Text += item.ToString() & vbCrLf05 Next You need to use a LINQ to Objects query to perform the following tasks: Obtain a list of duplicate part numbers.Order the list by part numbers.Provide the part numbers and the total count of part numbers in the results. Which code segment should you insert at line 02?
A. Dim results = (From n In parts _ Order By n _ Group n By n Into n1 = Group _ Select Key = n, Count = n1.Count()).Distinct()
B. Dim results = (From n In parts _ Group n By n Into n1 = Group _ Where n1.Count() > 1 _ Order By n1 _ Select Key = n, Count = n1.Count())
C. Dim results = (From n In parts _ Order By n _ Group n By n Into n1 = Group _ Where n1.Count() > 1 _ Select n1)
D. Dim results = (From n In parts _ Order By n _ Group n By n Into n1 = Group _ Where n1.Count() > 1 _ Select Key = n, Count = n1.Count())
Answer: D
QUESTION NO: 9
You are creating a Windows Forms application by using the .NET Framework 3.5. The application is used by a financial service provider. You discover that the service provider transfers large amounts of data by using XML. You need to read and validate the XML documents in the most time-efficient manner. Which technology should you use?
A. The XmlReader class
B. The XmlDocument class
C. The XmlResolver class
D. The LINQ to XML method
Answer: A
QUESTION NO: 10
You are creating a Windows Forms application for a book retailer by using the .NET Framework 3.5. You are creating a Windows form to allow users to maintain a list of books in an XML document. You write the following code segment. (Line numbers are included for reference only) 01 XmlDocument xmlDoc = new XmlDocument(); 02 XmlNode bookstore = xmlDoc.CreateElement(”bookstore”);03 xmlDoc.AppendChild(bookstore);04 XmlElement book = xmlDoc.CreateElement(”book”);05 book.SetAttribute(”ISBN”, strISBN);06 XmlElement title = xmlDoc.CreateElement(”title”);07 The variables strTitle and strISBN are already initialized with the necessary values. You need to ensure that after the form is complete the XML document has the following structure. <bookstore> <book ISBN=”n-nnn-nnnnn-nn”> <title>Title</title> </book></bookstore> Which code segment should you insert at line 07?
A. title.InnerText = strTitlebook.AppendChild(title)bookstore.AppendChild(book)
B. title.InnerText = strTitlebook.AppendChild(bookstore)bookstore.AppendChild(title)
C. title.Value = strTitlebook.AppendChild(title)bookstore.AppendChild(book)
D. title.Value = strTitlebookstore.AppendChild(title)book.AppendChild(bookstore)
Answer: A
QUESTION NO: 11
You are creating a Windows Forms application by using the .NET Framework 3.5. You need to populate a list box control along with category names by using a DataReader control. Which code segment should you use?
A. Dim reader As OleDbDataReaderDim cnnNorthwind As OleDbConnection = New _ OleDbConnection(connectionString)cnnNorthwind.Open()Dim cmdCategory As OleDbCommand = New _ OleDbCommand(”SELECT * FROM Categories”, cnnNorthwind)reader = cmdCategory.ExecuteReader()While reader.Read() lbCategories.Items.Add(reader(”CategoryName”))End WhilecnnNorthwind.Close()
B. Dim reader As OleDbDataReaderDim cnnNorthwind As OleDbConnection = New _ OleDbConnection(connectionString)cnnNorthwind.Open()Dim cmdCategory As OleDbCommand = New _ OleDbCommand(”SELECT * FROM Orders”, cnnNorthwind)reader = cmdCategory.ExecuteReader()While reader.NextResult() lbCategories.Items.Add(reader(”CategoryName”))End WhilecnnNorthwind.Close()
C. Dim reader As OleDbDataReaderDim cnnNorthwind As OleDbConnection = New _ OleDbConnection(connectionString)cnnNorthwind.Open()Dim cmdCategory As OleDbCommand = New _ OleDbCommand(”SELECT * FROM Orders”, cnnNorthwind)reader = cmdCategory.ExecuteReader()cnnNorthwind.Close()While reader.Read() lbCategories.Items.Add(reader(”CategoryName”))End WhilecnnNorthwind.Close()
D. Dim reader As OleDbDataReaderUsing cnnNorthwind As OleDbConnection = New _ OleDbConnection(connectionString) cnnNorthwind.Open() Dim cmdCategory As OleDbCommand = New _ OleDbCommand(”SELECT * FROM Orders”, cnnNorthwind) reader = cmdCategory.ExecuteReader()End UsingWhile reader.Read() lbCategories.Items.Add(reader(”CategoryName”))End WhilecnnNorthwind.Close()
Answer: A
QUESTION NO: 12
You are creating a Windows application for a financial services provider by using the .NET Framework 3.5. You write the following code segment in the form. (Line numbers are included for reference only.) 01 Dim queryString As String = _ “SELECT CategoryID, CategoryName FROM Categories”02 The connection string for the financial services database is stored in the variable named connString. You need to ensure that the form populates a DataGridView control named gridCAT. Which code segment should you add at line 02?
A. Dim adapter As OleDbDataAdapter = _ New OleDbDataAdapter(queryString, connString)Dim categories As DataSet = New DataSet()adapter.Fill(categories, “Categories”)gridCAT.DataSource = categories.Tables(0)
B. Dim conn As OleDbConnection = New OleDbConnection(connString)conn.Open()Dim cmd As OleDbCommand = New OleDbCommand(queryString, conn)Dim reader As OleDbDataReader = cmd.ExecuteReader()gridCAT.DataSource = reader
C. Dim adapter As OleDbDataAdapter = New _ OleDbDataAdapter(queryString, connString)Dim categories As DataSet = New DataSet()adapter.Fill(categories, “Categories”)gridCAT.DataSource = categories
D. Dim conn As OleDbConnection = New OleDbConnection(connString)conn.Open()Dim cmd As OleDbCommand = New OleDbCommand(queryString, conn)Dim reader As OleDbDataReader = cmd.ExecuteReader()gridCAT.DataSource = reader.Read()
Answer: A
QUESTION NO: 13
You are creating a Windows Forms application by using the .NET Framework 3.5. You write a code segment to connect to a Microsoft Access database and populate a DataSet. You need to ensure that the application meets the following requirements: It displays all database exceptions. It logs all other exceptions by using the LogExceptionToFile. Which code segment should you use?
A. Try categoryDataAdapter.Fill(dsCategory)Catch ex As SqlException MessageBox.Show(ex.Message, “Exception”) LogExceptionToFile(ex.Message)End Try
B. Try categoryDataAdapter.Fill(dsCategory)Catch ex As SqlException MessageBox.Show(ex.Message, “Exception”)Catch ex As Exception LogExceptionToFile(ex.Message)End Try
C. Try categoryDataAdapter.Fill(dsCategory)Catch ex As OleDbException MessageBox.Show(ex.Message, “Exception”)Catch ex As Exception LogExceptionToFile(ex.Message)End Try
D. Try categoryDataAdapter.Fill(dsCategory)Catch ex As OleDbException MessageBox.Show(ex.Message, “Exception”) LogExceptionToFile(ex.Message)End Try
Answer: C
QUESTION NO: 14
You are creating a Windows Forms application for inventory management by using the .NET Framework 3.5. The application provides a form that allows users to maintain stock balances. The form has the following features: A dataset named dsStockBalance to store the stock informationA business component named scInventory The scInventory component provides a method named Save. You need to ensure that only the modified stock balances of dsStockBalance are passed to the scInventory.Save method. Which code segment should you use?
A. If dsStockBalance.HasChanges() = True Then dsStockBalance.AcceptChanges()End IfdsUpdates = dsStockBalance.GetChanges()scInventory.Save(dsStockBalance)
B. If dsStockBalance.HasChanges() = True Then dsUpdates = dsStockBalance.GetChanges()End IfdsStockBalance.AcceptChanges()scInventory.Save(dsStockBalance)
C. If dsStockBalance.HasChanges() = True Then dsStockBalance.AcceptChanges() dsUpdates = dsStockBalance.GetChanges() scInventory.Save(dsUpdates)End If
D. If dsStockBalance.HasChanges() = True Then dsUpdates = dsStockBalance.GetChanges() dsStockBalance.AcceptChanges() scInventory.Save(dsUpdates)End If
Answer: D
QUESTION NO: 15
You are creating a Windows Forms application by using the .NET Framework 3.5. You use LINQ expressions to read a list of customers from the following XML file. <customers> <customer birthDate=”4/1/1968″> Paul Koch </customer> <customer birthDate=”7/5/1988″> Bob Kelly </customer> <customer birthDate=”3/24/1990″> Joe Healy </customer> <customer birthDate=”9/15/1974″> Matt Hink </customer> <customer birthDate=”1/7/2004″> Tom Perham </customer> <customer birthDate=”9/23/1946″> Jeff Hay </customer> <customer birthDate=”5/15/1947″> Kim Shane </customer> <customer birthDate=”4/24/1979″> Mike Ray </customer></customers> You need to obtain a list of names of customers who are 21 years of age or older. Which code segment should you use?
A. Dim customers As XDocument = XDocument.Load(”Customers.xml”)Dim results = From c In customers.Descendants(XName.Get(”customer”)) _ Where DateTime.Parse(c.Attribute(”birthDate”)).AddYears(21) < _ DateTime.Now _ Select c.Attribute(”Name”)
B. Dim customers As XDocument = XDocument.Load(”Customers.xml”)Dim results = From c In customers.Descendants(XName.Get(”customer”)) _ Where DateTime.Parse(c.Attribute(”birthDate”)).AddYears(21) < _ DateTime.Now _ Select FullName = c.Value
C. Dim customers As XDocument = XDocument.Load(”Customers.xml”)Dim results = From c In customers.Descendants(XName.Get(”customer”)) _ Where DateTime.Parse(c.Attribute(”birthDate”)).AddYears(21) < _ DateTime.Now _ Select c.Element(”customer”)
D. Dim customers As XDocument = XDocument.Load(”Customers.xml”)Dim results = From c In customers.Descendants() _ Where DateTime.Parse(c.Attribute(”birthDate”)).AddYears(21) < _ DateTime.Now _ Select FullName = c.Value
Answer: B
QUESTION NO: 16
You are creating a Windows Forms application by using the .NET Framework 3.5. You plan to modify a list of orders within a DataGridView control in the application. You need to ensure that a value is required in the first column of the grid control. Which code segment should you use?
A. Private Sub dataGridOrders_CellValidated( _ ByVal sender As Object, _ ByVal e As DataGridViewCellEventArgs) _ Handles dataGridOrders.CellValidated If e.ColumnIndex = 0 Then Dim cellValue = dataGridOrders(e.ColumnIndex, e.RowIndex).Value If cellValue = Nothing _ Or String.IsNullOrEmpty(cellValue.ToString()) Then dataGridOrders.EndEdit() End If End IfEnd Sub
B. Private Sub dataGridOrders_Validated( _ ByVal sender As Object, _ ByVal e As EventArgs) _ Handles dataGridOrders.Validated If dataGridOrders.CurrentCell.ColumnIndex = 0 Then Dim cellValue = dataGridOrders.Text If cellValue = Nothing Or _ String.IsNullOrEmpty(cellValue.ToString()) Then dataGridOrders.EndEdit() End If End IfEnd Sub
C. Private Sub dataGridOrders_Validating( _ ByVal sender As Object, _ ByVal e As CancelEventArgs) _ Handles dataGridOrders.Validating If dataGridOrders.CurrentCell.ColumnIndex = 0 Then Dim cellValue = dataGridOrders.Text If cellValue = Nothing Or _ String.IsNullOrEmpty(cellValue.ToString()) Then e.Cancel = True End If End IfEnd Sub
D. Private Sub dataGridOrders_CellValidating( _ ByVal sender As Object, _ ByVal e As DataGridViewCellValidatingEventArgs) _ Handles dataGridOrders.CellValidating If e.ColumnIndex = 0 Then If e.FormattedValue = Nothing _ Or String.IsNullOrEmpty(e.FormattedValue.ToString()) Then e.Cancel = True End If End IfEnd Sub
Answer: D
QUESTION NO: 17
You are creating a Windows Forms application by using the .NET Framework 3.5. The application displays employee names by using the TreeView control. You need to implement the drag-and-drop functionality in the TreeView control. Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)
A. Set the AllowDrop property to true. Create an event handler for the DragOver event.
B. Set the AllowDrop property to true. Create an event handler for the ItemDrag event to call the DoDragDrop method.
C. Set the AllowDrop property to true. Create an event handler for the DragEnter event to call the DoDragDrop method.
D. Create an event handler for the DragDrop event to handle the move or copy by itself.
E. Create an event handler for the DragEnter event to handle the move or copy by itself.
Answer: BD
QUESTION NO: 18
You are creating a Windows Forms application by using the .NET Framework 3.5. You plan to display detailed help instructions for each control in the form. You create a help file. You configure a HelpProvider component on the form. You need to display the help file for the control that is focused when the F1 key is pressed. Which method of the HelpProvider class should you call for each control?
A. SetShowHelp
B. SetHelpString
C. SetHelpKeyword
D. SetHelpNavigator
Answer: A
QUESTION NO: 19
You are creating a Windows Forms application by using the .NET Framework 3.5. Users use the application to process and approve invoices. A list of recently accessed invoices is stored in the users settings section of the App.config file. You need to maintain the list of invoices from the last persisted state. What should you do?
A. Use the Properties.Settings object during runtime.
B. Use the Properties.Settings.Default object during runtime.
C. Use the ConfigurationManager.AppSettings object during runtime.
D. Use the ConfigurationManager.GetSection method during runtime.
Answer: B
QUESTION NO: 20
You are creating a Windows Forms application by using the .NET Framework 3.5. You have resource files in five different languages. You need to test the application in each language. What should you do?
A. Set the CurrentCulture property explicitly to the respective culture for each language.
B. Set the CurrentCulture property explicitly to IsNeutralCulture for each language.
C. Set the CurrentUICulture property explicitly to IsNeutralCulture for each language.
D. Set the CurrentUICulture property explicitly to the respective culture for each language.
Answer: D