User:Foxall/answers
./ ADD NAME=APP01.HTM
Appendix A. Answers to Quizzes/Exercises
Answers to Hour 1
Answers to Hour 2
Answers to Hour 3
Answers to Hour 4
Answers to Hour 5
Answers to Hour 6
Answers to Hour 7
Answers to Hour 8
Answers for Hour 9
Answers to Hour 10
Answers to Hour 11
Answers to Hour 12
Answers to Hour 13
Answers to Hour 14
Answers to Hour 15
Answers to Hour 16
Answers to Hour 17
Answers to Hour 18
Answers for Hour 19
Answers to Hour 20
Answers to Hour 21
Answers to Hour 22
Answers for Hour 23
Answers for Hour 24
Top
./ ADD NAME=APP01LEV1SEC01.HTM
Answers to Hour 1
1:
What type of C# project creates a standard Windows program?
A1:
Windows Application project
2:
What window is used to change the attributes (location, size, and so on) of a form or control?
A2:
Properties window
3:
How do you access the default event (code) of a control?
A3:
Double-click the control
4:
What property of a PictureBox do you set to display an image?
A4:
The Image property
5:
What is the default event for a Button control?
A5:
Click event
Top
./ ADD NAME=APP01LEV1SEC02.HTM
Answers to Hour 2
1:
How can you make the Visual Studio Start Page appear at startup if this feature has been disabled?
A1:
Change the At Startup property of the project.
2:
Unless instructed otherwise, you are to create what type of project when building examples in this book?
A2:
Windows Application project
3:
To make a docked design window appear when you hover over its tab and disappear when you move the mouse away from it, you change what setting of the window?
A3:
Auto Hide
4:
How do you access the Toolbars menu?
A4:
Choose Toolbars from the View menu or right-click any toolbar.
5:
What design window do you use to add controls to a form?
A5:
The toolbox
6:
What design window is used to change the attributes of an object?
A6:
The Properties window
7:
To modify the properties of a project, you must select the project in what design window?
A7:
Solution Explorer
8:
Which Help feature adjusts the links it displays to match what it is you are doing?
A8:
Dynamic Help
Top
./ ADD NAME=APP01LEV1SEC03.HTM
Answers to Hour 3
1:
True or False: C# is a true object-oriented language.
A1:
True.
2:
An attribute that defines the state of an object is called a what?
A2:
Property
3:
To change the value of a property, the property must be referenced on which side of an equal sign?
A3:
The left side
4:
What is the term for when a new object is created from a template?
A4:
Instantiation
5:
An external function of an object (one that is available to code using an object) is called a what?
A5:
Method
6:
True or False: A property of an object can be another object.
A6:
True. Such properties are called object properties.
7:
A group of like objects is called what?
A7:
Collection
8:
What tool is used to explore the members of an object?
A8:
Object Browser
Top
./ ADD NAME=APP01LEV1SEC04.HTM
Answers to Hour 4
1:
Name three things that can cause events to occur.
A1:
The operating system, a user, objects
2:
True or False: All objects support the same set of events.
A2:
False. Each object supports a set of events specific to itself, or no events at all.
3:
What is the default event type for a button?
A3:
Click
4:
The act of an event calling itself in a loop is called what?
A4:
Recursion
5:
What is the easiest way to access a control's default event handler?
A5:
Double-click the control in the form designer.
6:
All control events pass a reference to the control causing the event. What is the name of the parameter that holds this reference?
A6:
sender
Top
./ ADD NAME=APP01LEV1SEC05.HTM
Answers to Hour 5
1:
True or False: The text displayed in the form's title bar is determined by the value in the TitleBarText property.
A1:
False. The title bar text is determined by the Text property.
2:
The named color Control is what kind of color?
A2:
A system color. System colors are determined at runtime by the user's Windows settings.
3:
In what three places are a form's icon displayed?
A3:
In the form's title bar, in the taskbar when the form is minimized, and in the task list when the user presses Alt+Tab.
4:
A window with a smaller than normal title bar is called what?
A4:
A tool window
5:
For a Minimize or Maximize button to be visible on a form, what other element must be visible?
A5:
The ControlBox must be visible.
6:
What, in general, is the best value to use for the StartPosition property of a form?
A6:
CenterParent
7:
To maximize, minimize, or restore a form in code, you set what property?
A7:
The WindowState property
8:
True or False: To display a form, you must create a variable in code.
A8:
True
9:
What property do you set to make a hidden form appear?
A9:
The form's Visible property.
Top
./ ADD NAME=APP01LEV1SEC06.HTM
Answers to Hour 6
1:
True or False: The first control selected in a series is always made the active control.
A1:
False
2:
How many methods are there to add a control to a form from the toolbox?
A2:
Three: double-click, drag and drop, select and draw
3:
If you double-click a tool in the toolbox, where on the form is it placed?
A3:
Upper-left corner
4:
Which property fixes an edge of a control to an edge of a form?
A4:
Anchor
5:
Which property do you change to hide the grid on a form?
A5:
DrawGrid
6:
Which menu contains the functions for spacing and aligning controls?
A6:
The Format menu
7:
Which property do you set to make a form a MDI parent?
A7:
IsMdiContainer
Top
./ ADD NAME=APP01LEV1SEC07.HTM
Answers to Hour 7
1:
Which control would you use to display text that the user can't edit?
A1:
A Label control
2:
What common property is shared by the Label control and text box 2and whose value determines what the user sees in the control?
A2:
Text
3:
To change the Height of a text box, you must set what property?
A3:
You must set the MultiLine property to true.
4:
What is the default event of a Button control?
A4:
The Click event.
5:
A button whose Click event is triggered when the user presses Enter, regardless of the control that has the focus, is called an…?
A5:
Accept button.
6:
Which control would you use to display a yes/no value to a user?
A6:
A check box.
7:
How would you create two distinct sets of mutually exclusive option buttons?
A7:
Place each set of option buttons on a different container control, such as a group box.
8:
To manipulate items in a list, you use what collection?
A8:
The Items collection of the control.
9:
What method adds an item to a list in a specific location?
A9:
The Insert method of the Items collection.
Top
./ ADD NAME=APP01LEV1SEC08.HTM
Answers to Hour 8
1:
What increment of time is applied to the Interval property of the Timer control?
A1:
Milliseconds
2:
What collection is used to add new tabs to a Tab control?
A2:
The TabPages collection
3:
What property returns the index of the currently selected tab?
A3:
The SelectedIndex property of the control
4:
True or False: You should use different Image List controls for storing images of different sizes.
A4:
True
5:
To see columns in a List View control, the View property must be set to what?
A5:
Details
6:
The additional columns of data that can be attached to an item in a list view are stored in what collection?
A6:
The SubItems collection
7:
What property of what object would you use to determine how many items are in a List View?
A7:
The Count property of the Items collection
8:
Each item in a Tree View is called a what?
A8:
Node
9:
How do you make a node the child of another node?
A9:
Add it to the Nodes collection of the first node.
Top
./ ADD NAME=APP01LEV1SEC09.HTM
Answers for Hour 9
1:
True or False: Form menu bars are created using the Context Menu control.
A1:
False. They are created using the Main Menu control.
2:
To create an accelerator or hotkey, preface the character with a(n):
A2:
Ampersand (&)
3:
If you've designed a menu using a Main Menu control, but that menu isn't visible on the form designer, how do you make it appear?
A3:
Click the Main Menu control at the bottom of the form designer.
4:
To place a check mark next to a menu item, you set what property of the item?
A4:
The Checked property.
5:
How do you add code to a menu item?
A5:
Double-click the item while in Edit mode.
6:
Toolbar items are part of what collection?
A6:
The Buttons collection
7:
To create a separator on a toolbar, you create a new button and set what property?
A7:
The Style property to Separator.
8:
True or False: Every button on a toolbar has its own Click event.
A8:
False. All buttons share a ButtonClick event.
9:
What must you do to have panels appear on a status bar?
A9:
Set the ShowPanels property to true.
Top
./ ADD NAME=APP01LEV1SEC10.HTM
Answers to Hour 10
1:
What object is used to draw to a surface?
A1:
Graphics
2:
To set a Graphics object to draw to a form directly, you call what method of the form?
A2:
CreateGraphics()
3:
What object defines the characteristics of a line? A fill pattern?
A3:
Pens define lines, brushes define fill patterns.
4:
How do you make a color property adjust with the user's Windows settings?
A4:
Assign a system color to the property
5:
What object is used to define the bounds of a shape to be drawn?
A5:
Rectangle
6:
What method do you call to draw an irregular ellipse? A circle?
A6:
Ellipses and circles are both drawn using the DrawEllipse() method.
7:
What method do you call to print text on a Graphics surface?
A7:
DrawString()
8:
To ensure that graphics persist on a form, the graphics must be drawn on the form in what event?
A8:
The form's Paint event
Top
./ ADD NAME=APP01LEV1SEC11.HTM
Answers to Hour 11
1:
What are the entities called that are used to house methods?
A1:
Classes
2:
True or False: To access methods in a class module, you must first create an object.
A2:
False. Static methods do not require that an object be instantiated for the static methods to be called.
3:
Data that has been passed into a method by a calling statement is called a
A3:
Parameter
4:
To pass multiple arguments to a method, separate them with a
A4:
Comma
5:
The situation in which a method or set of methods continue to call each other in a looping fashion is called
A5:
Recursion
6:
How do you attach a task to a code statement?
A6:
Right-click the statement and choose Add Task List Shortcut from the context menu.
Top
./ ADD NAME=APP01LEV1SEC12.HTM
Answers to Hour 12
1:
What data type would you use to hold currency values?
A1:
decimal
2:
Which data type can be used to hold any kind of data and essentially serves as a generic data type?
A2:
object
3:
What values does C# support for type bool?
A3:
true or false
4:
What can you create to eliminate magic numbers by defining a literal value in one place?
A4:
Constant
5:
What type of data element can you create in code that can have its value changed as many times as necessary?
A5:
Variable
6:
What are the first and last indexes of an array dimensioned using string_strMyArray[5]?
A6:
First index = 0, last index = 4
7:
What word is given to describe the visibility of a constant or variable?
A7:
Scope
8:
In general, is it best to limit the scope of a variable or to use the widest scope possible?
A8:
It is usually best to limit scope.
Top
./ ADD NAME=APP01LEV1SEC13.HTM
Answers to Hour 13
1:
To get only the remainder of a division operation, you use which operator?
A1:
%
2:
Which operation is performed first in the following expression�the addition or the multiplication?
A2:
Multiplication
3:
Does this expression evaluate to true or to false?
((true || true) && false) == !true
A3:
true
4:
Which Boolean operator performs a logical negation?
A4:
!
5:
The process of appending one string to another is called?
A5:
Concatenation
6:
What property can be used to return the month of a given date?
A6:
Month
Top
./ ADD NAME=APP01LEV1SEC14.HTM
Answers to Hour 14
1:
Which decision construct should you use to evaluate a single expression to either true or false?
A1:
if
2:
Evaluating expressions to true or false for both types of decision constructs is accomplished using ________ logic.
A2:
Boolean
3:
If you want code to execute when the expression of an if statement evaluates to false, include an ____ clause.
A3:
else
4:
Which decision construct should you use when evaluating the result of an expression that may equate to one of many possible values?
A4:
switch
5:
Is it possible that more than one case statement may have its code execute?
A5:
Yes, the case statement requires a jump-statement. A valid jump-statement is goto case expression, which transfers control to a specific switch-case label or the default label.
6:
True or False: You can use goto to jump code execution to a different method.
A6:
False. goto can be used only to divert code in the method in which the goto exists.
7:
To use goto to jump execution to a new location in code, what must you create as a pointer to jump to?
A7:
A code label
Top
./ ADD NAME=APP01LEV1SEC15.HTM
Answers to Hour 15
1:
True or False: You have to know the start and end values of a for loop at design time to use this type of loop.
A1:
False. You must know these values at runtime, but it isn't necessary to know them at design time.
2:
Is it possible to nest loops?
A2:
Yes, and this is a common thing to do.
3:
What type of loop would you most likely need to create if you didn't have any idea how many times the loop would need to occur?
A3:
do…while
4:
If you evaluate the expression in a do…while on the while statement, is it possible that the code within the loop may never execute?
A4:
No. When you evaluate the expression on the while statement, the code within the loop is guaranteed to execute at least once.
5:
What statement do you use to terminate a do…while without evaluating the expression on the do or while statements?
A5:
break
Top
./ ADD NAME=APP01LEV1SEC16.HTM
Answers to Hour 16
1:
What type of error prevents C# from compiling and running code?
A1:
A build error
2:
What is the name of a runtime error: an error that usually occurs as a result of attempting to process inappropriate data?
A2:
An exception
3:
What character is used to denote a single line comment?
A3:
The double slashes character (//)
4:
To halt execution at a specific statement in code, you set a what?
A4:
Break point
5:
Explain the yellow arrow and red circles that can appear in the gray area in the code editor.
A5:
The yellow arrow denotes the next statement to be processed. Red circles are used to mark break points.
6:
What IDE window would you use to poll the contents of a variable in Break mode?
A6:
The Command window
7:
True or False: You must always specify a catch section in a try structure.
A7:
False
Top
./ ADD NAME=APP01LEV1SEC17.HTM
Answers to Hour 17
1:
To create objects, you must first create a template. This template is called a:
A1:
Class
2:
One of the primary benefits of object-oriented programming is that objects contain both their data and their code. This is called:
A2:
Encapsulation
3:
With static classes, public variables and routines are always available to code via the static class in other modules. Is this true with public variables and routines in classes?
A3:
No. To access the public variables and routines, an object must be instantiated from the class.
4:
True or False: Each object derived from a class has its own set of class-level data.
A4:
True
5:
What must you do to create a property that can be read but not changed by client code?
A5:
Create a property procedure that includes the get accessor, but not the set accessor.
6:
What is the best way to store the internal value of a property within a class?
A6:
As a private class-level variable
7:
Which is generally superior, early binding or late binding?
A7:
Early binding
8:
What is the best way to release an object you no longer need?
A8:
Call the object's Dispose() method if it has one, and then set the object variable to null.
Top
./ ADD NAME=APP01LEV1SEC18.HTM
Answers to Hour 18
1:
What minimal argument should you supply when calling MessageBox.Show()?
A1:
The prompt argument, the string for the message.
2:
If you don't supply a value for the title parameter of MessageBox.Show(), what gets displayed in the title bar of the message?
A2:
Nothing
3:
What type of data is always returned by the MessageBox.Show() method?
A3:
A DialogResult
4:
Which event fires first, the KeyUp or KeyPress event?
A4:
KeyPress
5:
How do you determine which button is being pressed in a mouse-related event?
A5:
Use the Buttons property of the e object in the event handler.
Top
./ ADD NAME=APP01LEV1SEC19.HTM
Answers for Hour 19
1:
True or False: The Open File dialog box automatically opens a file.
A1:
False. The control returns the name of the file the user wants to open, but it doesn't open the file.
2:
What symbol is used to separate a filter description from its extension?
A2:
The pipe (|) symbol
3:
What objects are used to manipulate files?
A3:
System.IO.File and System.IO.FileInfo
4:
What arguments are required by System.IO.File.Copy()?
A4:
Two arguments are required. The first is the name of the current file; the second is the name of the file to create as a result of the copy.
5:
How would you rename a file?
A5:
Use System.IO.File.Move(), using the same path but a different filename.
6:
True or False: Files deleted with System.IO.File.Delete() are sent to the Recycle Bin.
A6:
False
7:
What objects are used to manipulate folders?
A7:
System.IO.Directory and System.IO.DirectoryInfo. Sometimes Microsoft calls them folders, sometimes directories. In .NET, however, it's usually directory.
Top
./ ADD NAME=20.HTM
Answers to Hour 20
1:
Before you can early bind objects in an automation server, you must do what?
A1:
Create a reference to a type library.
2:
What is the most likely cause of not seeing a type library listed in the Add References dialog box?
A2:
You don't have the component installed on your computer.
3:
For C# to use a COM library, it must create a:
A3:
Wrapper
4:
To manipulate a server via automation, you manipulate:
A4:
An object variable referencing an object in the server's object model
5:
To learn about the object library of a component, you should:
A5:
Read the documentation or use the Object Browser.
Top
./ ADD NAMEC21.HTM
Answers to Hour 21
1:
What is the name of the data access components used in the .NET Framework?
A1:
ADO.NET
2:
What is the name given to a collection of DataRows?
A2:
DataTable
3:
How do I get data into and out of a DataTable?
A3:
Use the Fill() and Update() methods of the ADO.NET DataAdapter.
4:
What object is used to connect to a data source?
A4:
The connection object appropriate to the data source (SqlConnection or OleDbConnection)
5:
What argument of a connection string contains information about the type of data being connected to?
A5:
The Provider= argument
6:
The functionality of a DataTable (read-only, updateable, and so forth) is determined by what?
A6:
The DataTable always has the same functionality, regardless of the source of the data.
7:
What are the two .NET data providers supplied as part of the .NET Framework?
A7:
The OleDb .NET Data Provider and the SqlClient .NET Data Provider
8:
What method of a DataTable object do you call to create a new row?
A8:
NewRow()
Top
./ ADD NAME=APP01LEV1SEC22.HTM
Answers to Hour 22
1:
To create a custom setup program, you start by creating what type of Visual Studio project?
A1:
The project type is Setup Project, which can be found in the Setup and Deployment Projects folder.
2:
The final build file of a project (EXE, DLL, and so on) is referred to as the what?
A2:
Output of the project
3:
True or False: To include the output of a project, the project must be added to the solution containing the setup program.
A3:
True
4:
Which build option creates smaller and faster builds?
A4:
Release builds are smaller and faster than Debug builds.
5:
How do you add a file to an installation?
A5:
Open the Project menu, open the Add submenu, and choose File.
6:
If the Project menu doesn't have the menu options for creating a setup program, what might be wrong?
A6:
You probably have a project other than the Setup Project selected in the Solution Explorer.
7:
How do you add folders to the custom setup program?
A7:
Right-click the File System on the Target Machine item in the left pane of the Setup Project.
8:
How do you create a shortcut for a file in a setup program?
A8:
Right-click the file and choose the appropriate menu item.
Top
./ ADD NAME=APP01LEV1SEC23.HTM
Answers for Hour 23
1:
What does XML stand for?
A1:
eXtensible Markup Language
2:
An element is designated in an XML document using the what?
A2:
Starting and ending tags
3:
True or False: XML tag names are case sensitive.
A3:
True
4:
What is the name of the protocol used by .NET to marshal object requests across the Web?
A4:
SOAP (Simple Object Access Protocol)
5:
What forms engine is used to create forms that run over the Internet?
A5:
Web Forms
6:
Which forms engine provides for faster response to user interaction?
A6:
Windows Forms
7:
Where is the .NET Framework installed for Windows Forms applications? Web Forms applications?
A7:
The .NET Framework is installed on the user's computer for Windows applications and on the Web server for Web Forms applications.
8:
What is the name of the ASP.NET technology used to expose application logic as objects over the Web?
A8:
XML Web services
Top
./ ADD NAME=APP01LEV1SEC24.HTM
Answers for Hour 24
1:
The classes and technology that make up .NET's underlying infrastructure are called what?
A1:
The .NET Framework
2:
What is the name of the shared .NET runtime?
A2:
The Common Language Runtime (CLR)
3:
True or False: Each .NET language uses its own code editor and debugging tools.
A3:
False. All .NET languages share the same IDE and the same debugging tools. These are just a few of the benefits of the Common Language Runtime.
4:
True or False: Code that runs within the Common Language Runtime is called unmanaged code.
A4:
False. It is called managed code because it is managed by the runtime.
5:
Code written in a .NET language such as C# is compiled to what?
A5:
Intermediate Language code (IL)
6:
What are namespaces?
A6:
Namespaces are the "nodes" in the hierarchical structure of classes in the .NET environment.
7:
One of the things that gives .NET its multilanguage capabilities is that all data is declared and managed in the same way across all languages. This is handled by .NET's what?
A7:
Common Type System
8:
What destroys objects, freeing all the resources that they consume?
A8:
.NET's garbage collector
Top