Appendix A: Questions and Answers

Appendix A

Questions and Answers

Chapter 1: Introduction to the .NET Framework

  1. Briefly describe the major components of the .NET Framework and describe what each component does.

    The .NET Framework consists of two primary parts: the common language runtime, which manages application execution, enforces type safety, and manages memory reclamation, and the .NET base class library, which consists of thousands of predeveloped classes that can be used to build applications.

  2. Briefly explain what is meant by a reference type and a value type.

    A value type holds all of the data represented by the variable within the variable itself. A reference type contains a reference to a memory address that holds the data instead of the actual data itself.

  3. How do you enable your application to use .NET base class library members without referencing their fully qualified names?

    Use the Imports keyword (Visual Basic .NET) or the using keyword (Visual C#) to make a .NET Framework namespace visible to your application.

  4. Briefly describe how garbage collection works.

    The garbage collector is a thread that runs in the background of managed .NET applications. It constantly traces the reference tree and attempts to find objects that are no longer referenced. When a nonreferenced object is found, its memory is reclaimed for later use.

  5. Briefly describe what members are, and list the four types of members.

    Members are the parts of a class or a structure that hold data or implement functionality. The primary member types are fields, properties, methods, and events.

  6. Explain what constructors and destructors are and describe what they are used for.

    The constructor is the method that initializes a class or structure and is run when a type is first instantiated. It is used to set default values and perform other tasks required by the class. A destructor is the method that is run as the object is being reclaimed by garbage collection. It contains any code that is required for cleanup of the object.

  7. Briefly explain the difference between Public (public), Friend (internal), and Private (private) access levels as they apply to user-defined types and members.

    In user-defined types, Public (public) classes can be instantiated by any element of the application. Friend (internal) classes can be instantiated only by members of the same assembly, and Private (private) classes can be instantiated only by themselves or types they are nested in. Likewise, a Public (public) member can be accessed by any client in the application, a Friend (internal) member can be accessed only from members of the same assembly, and Private (private) members can be accessed only from within the type.

  8. Do you need to instantiate a class before accessing a Shared (static) member? Why or why not?

    Because a Shared (static) member belongs to the type rather than to any instance of the type, you can access the member without first creating an instance of the type.

  9. Briefly describe how a class is similar to a structure. How are they different?

    Both classes and structures can have members such as methods, properties, and fields, both use a constructor for initialization, and both inherit from System.Object. Both classes and structures can be used to model realworld objects.

    Classes are reference types, and the memory that holds class instances is allocated on the heap. Structures are value types, and the memory that holds structure instances is allocated on the stack.

Chapter 2: Creating the User Interface

  1. You are creating an application for a major bank. The application should integrate seamlessly with Microsoft Office XP, be easy to learn, and instill a sense of corporate pride in the users. Name two ways you might approach these goals in the user interface.

    Design the user interface to mimic the look and feel of Microsoft Office XP, which will allow users of Office XP to immediately feel comfortable with the new application. Integration of the corporate logo and other visual elements associated with the company will aid in identification of the program with the company.

  2. You are writing an application that needs to display a common set of controls on several different forms. What is the fastest way to approach this problem?

    Create a single form that incorporates the common controls, and use visual inheritance to create derived forms.

  3. If you wanted to prompt a user for input every time a form received the focus, what would be the best strategy for implementing this functionality?

    Write an event handler for the Activated event that implements the relevant functionality.

  4. Describe two ways to set the tab order of controls on your form.

    You can set the tab order in Visual Studio by choosing Tab Index from the View menu and clicking each control in the order you desire. Alternatively, you can set the TabIndex property either in code or in the Properties window.

  5. What is an extender provider, and what does one do?

    Extender providers are components that provide additional properties to controls on a form. Examples include the ErrorProvider, HelpProvider, and ToolTip components. They can be used to provide additional information about particular controls to the user in the user interface.

  6. Explain when you might implement a shortcut menu instead of a main menu.

    If every possible option is exposed on a main menu, the menu can become busy and hard to use. Shortcut menus allow less frequently used options to be exposed only in situations where they are likely to be used.

  7. Describe what is meant by field-level validation and form-level validation.

    Field-level validation is the process of validating each individual field as it is entered into a form. Form-level validation describes the process of validating all of the data on a form before submitting the form.

  8. Describe how to retrieve the ASCII key code from a keystroke. How would you retrieve key combinations for non-ASCII keys?

    Keystrokes can be intercepted by handling the KeyPress and KeyDown events. Both of these events relay information to their handling methods in the form of their EventArgs. The KeyPressEventArgs, relayed by the Key-Press event, exposes the ASCII value of the key pressed in the KeyPressEventArgs. KeyChar property. The KeyEventArgs, relayed by the KeyDown event, exposes properties that indicate whether non-ASCII keys such as ALT, CTRL, or Shift have been pressed. To retrieve the ASCII key code from a keystroke, you would handle the KeyPress event and get that information from the KeyPressEventArgs.KeyChar property. To retrieve non-ASCII information, you would handle the KeyDown event and use the properties exposed by the KeyEventArgs instance.

  9. Describe in general terms how to add a control to a form at run time.

    You must first declare and instantiate a new instance of the control. Then, you must add the control to the forms Controls collection. Once the control has been added to the Controls collection, you must manually set properties that govern the controls position and appearance.

Chapter 3: Types and Members

  1. Explain when a type conversion will undergo an implicit cast and when you must perform an explicit cast. What are the dangers associated with explicit casts?

    Types can be implicitly converted when the conversion can always take place without any potential loss of data. When a potential loss of data is possible, an explicit cast is required. If an explicit cast is improperly performed, a loss of data precision can result, or an exception can be thrown.

  2. Explain why you might use enums and constants instead of their associated literal values.

    Enums and constants make code easier to read and maintain by substituting human-legible tokens for frequently used constant values.

  3. Briefly summarize the similarities and differences between arrays and collections.

    Arrays and collections allow you to manage groups of objects. You can access a particular object by index in both arrays and collections, and you can use For Each Next (foreach) syntax to iterate through the members of arrays and most collections. Arrays are fixed in length, and members must be initialized before use. Members of collections must be declared and initialized outside of the collection, and then added to the collection. Collections provided in the System.Collections namespace can grow or shrink dynamically, and items can be added or removed at run time.

  4. Explain how properties differ from fields. Why would you expose public data through properties instead of fields?

    Properties allow validation code to execute when values are accessed or changed. This allows you to impose some measure of control over when and how values are read or changed. Fields cannot perform validation when being read or set.

  5. Explain what a delegate is and how one works.

    A delegate acts like a strongly typed function pointer. Delegates can invoke the methods that they reference without making explicit calls to those methods.

  6. Briefly explain how to convert a string representation of a number to a numeric type, such as an Integer or a Double.

    All numeric data types have a Parse method that accepts a string parameter and returns the value represented by that string cast to the appropriate data type. You can use the Parse method of each data type to convert strings to that type.

  7. What are the two kinds of multidimensional arrays? Briefly describe each.

    Multidimensional arrays can be either rectangular arrays or jagged arrays. A rectangular array can be thought of as a table, where each row has the same number of columns. Rectangular arrays with more than two dimensions continue this concept, where each member of each dimension has the same number of members of each other dimension. Jagged arrays can be thought of as an array of arrays. A two-dimensional jagged array is like a table where each row might have a different number of columns.

Chapter 4: Object-Oriented Programming and Polymorphism

  1. Briefly explain encapsulation and why it is important in object-oriented programming.

    Encapsulation is the principle that all of the data and functionality required by an object be contained by that object. This allows objects to exist as independent, interchangeable units of functionality without maintaining dependencies on other units of code.

  2. What is method overloading, and when is it useful?

    Method overloading allows you to create several methods with the same name but different signatures. Overloading is useful when you want to provide the same or similar functionality to different sets of parameters.

  3. You need to create several unrelated classes that each exposes a common set of methods. Briefly outline a strategy that will allow these classes to polymorphically expose that functionality to other classes.

    Factor the common set of methods into an interface, and then implement that interface in each class. Each class can then be implicitly cast to that interface and can polymorphically interact with other classes.

  4. You need to create several classes that provide a core set of functionality but each must be able to interact with a different set of objects. Outline a strategy for developing these classes with the least development time.

    Create a single class that implements all of the common functionality required by these classes. Then, use inheritance to create derived classes that are specific for each individual case.

  5. Describe an abstract class and explain when one might be useful.

    An abstract class is a class that cannot be instantiated but must be inherited. It can contain both implemented methods and abstract methods, which must be implemented in an inheriting class. Thus, it can define common functionality for some methods, a common interface for other methods, and leave more detailed implementation up to the inheriting class.

Chapter 5: Testing and Debugging Your Application

  1. Describe Break mode and some of the available methods for navigating in Break mode.

    Break mode allows you to observe program execution on a line-by-line basis. You can navigate program execution in Break mode by using Step Into, Step Over, Step Out, Run To Cursor, and Set Next Statement.

  2. When would you use the Watch window?

    You would use the Watch window to observe the values of application variables while in Break mode.

  3. You are deploying a beta version of a large application and want to collect performance data in text files while the application is in use. Briefly describe a strategy for enabling this scenario.

    Place Trace statements that report the data of interest throughout the application. Create a TextWriterTraceListener and add it to the Listeners collection. Create Trace switches that control when Trace statements are executed. Configure the TextWriterTraceListener to write output to a text file. Then, compile and deploy the application with Trace defined, and enable the Trace switches in the application .config file.

  4. When testing a method, should you test data that is known to be outside of the bounds of normal operation? Why or why not?

    Yes. In addition to testing normal data operation, you must test known bad input to ensure that your application can recover from input errors without a catastrophic application failure.

  5. Briefly explain what each segment of a Try Catch Finally (try...catch...finally) block does.

    The Try (try) block encloses code that is to be executed. If an exception is thrown, it can be caught in an appropriate Catch (catch) block where code that will allow the application to handle the execution will be executed. The Finally (finally) block contains any code that must be executed whether or not the exception is handled.

Chapter 6: Data Access with ADO.NET

  1. What are the major components of a Data Provider, and what function does each fulfill?

    An ADO.NET Data Provider is a suite of components designed to facilitate data access. Every Data Provider minimally includes a Connection object that provides the actual connection to the data source, a Command object that represents a direct command to the data source, a DataReader object that provides connected, forward-only, read-only access to a database, and a DataAdapter that facilitates disconnected data access.

  2. Briefly contrast connected and disconnected data access in ADO.NET.

    In ADO.NET, connected data access is available through the DataReader, which is a lightweight class designed to provide very fast and efficient data access. It is severely limited, however, in that it can only provide forward-only data access, it does not allow editing, and it requires the exclusive use of a Connection object. In contrast, disconnected data access is facilitated by a DataAdapter, which manages the commands required for selecting and updating data. The DataAdapter executes a SELECT command against a database, opening a data connection just long enough to retrieve the data, and loads the data into a DataSet, which is an in-memory copy of the data. When the data is ready to be updated, the Data Provider manages the updates in the same way, generating the appropriate commands to update the database and keeping the connection open just long enough to execute those commands.

  3. What are the three possible settings for the CommandType property of a SqlCommand object or an OleDbCommand object, and what does each mean?

    A Command object can have a CommandType property setting of Text, StoredProcedure, or TableDirect. When set to Text, the command executes the SQL string that is stored in the Command object s CommandText property. When set to StoredProcedure, the command accesses a procedure stored on the database and returns the results. A CommandText setting of TableDirect indicates that the command should return the entire contents of the table indicated by the CommandText property.

  4. How could you execute DDL commands, such as ALTER or CREATE TABLE, against a database with ADO.NET?

    You must use a Command object to execute DDL commands. You can set the CommandType property to Text and enter the appropriate DDL command in the CommandText property. Then call Command.ExecuteNonQuery to execute the command.

  5. Briefly discuss the advantages and disadvantages of using typed DataSet objects.

    Typed DataSet objects allow you to work with data that is represented as members of the .NET common type system. This allows your applications to be aware of the types of data returned in a DataSet and serves to eliminate errors resulting from invalid casts, as any type mismatches are caught at compile time. Untyped DataSet objects, however, are useful if you do not know the structure of your data, and can be used with any data source.

  6. How can you manage data currency on a form with several bound controls?

    Every data source on a form has an associated CurrencyManager object that keeps that of the current record with respect to bound controls. For convenience, all of the CurrencyManager objects represented on a form are exposed through the form s BindingContext property. The Position of the CurrencyManager can be changed, allowing navigation through the records.

  7. Describe how to use a DataView to filter or sort data.

    You can apply sort criteria to a DataView by setting the Sort property to the name of a column or columns to be sorted by. The data represented in a DataView object can be filtered by setting the RowFilter property to a valid filter expression.

  8. Briefly describe an XmlDataDocument and how it relates to a DataSet.

    An XmlDataDocument is an in-memory representation of data in a hierarchical XML format. Each XmlDataDocument is synchronized with a DataSet. Whenever changes are made to one object, the other is instantly updated. Thus, you can use the XmlDataDocument to perform XML manipulations on a DataSet.

  9. What are the four major parts of a SQL SELECT statement? Briefly describe each one.

    The four major parts of a SELECT statement are SELECT, FROM, WHERE, and ORDER BY. SELECT specifies the fields to be retrieved. FROM specifies the table from which the records are to be retrieved. WHERE allows you to specify filter criteria for the records to be retrieved, and ORDER BY allows you to specify a sort order for the records.

  10. In Visual Basic .NET or Visual C# programming, when would you use Structured Query Language (SQL)? How are they executed?

    ADO.NET handles most of the database communication for you behind-the-scenes. You would only use SQL statements when generating ad-hoc queries for the database. You execute SQL statements by using a DataCommand object. Statements the return records, such as SELECT statements, are executed using the ExecuteQuery method. You can also return a single value with a SELECT statement by using the ExecuteScalar method. To execute non-value returning statements, such as DELETE, INSERT INTO, or UPDATE statements, use the ExecuteNonQuery method.

  11. What is meant by a SQL injection attack? How can you prevent them from occurring in your application?

    SQL injection attacks occur when a malicious user attempts to execute SQL code by passing a SQL string to the application through user input. You can guard against SQL injection attacks by validating the format of all strings derived from user input that are used to form ad hoc SQL statements.

  12. How can you read XML data into a dataset? How would you write data in a dataset to an XML file? How would you retrieve a string representation of the XML contained within a dataset? Describe each in general terms.

    To read data from an XML file into a dataset, you can use the ReadXML method of the dataset, specifying the stream or file that contains the XML data. To write data to a file, you can use the WriteXML method of the dataset, again specifying either the file or the stream that represents the file. The GetXML method of the dataset can be used to retrieve a string representation of the XML data contained by a dataset.

Chapter 7: Creating Controls Using the .NET Framework

  1. Briefly describe the three types of user-developed controls and how they differ.

    The three types of user-developed controls are inherited controls, user controls, and custom controls. An inherited control derives from a standard Windows Forms control and inherits the look, feel, and functionality of that control. User controls allow you to combine standard Windows Forms controls and bind them together with common functionality. Custom controls inherit from Control and are the most development-intensive kind of control. Custom controls must implement all their own code for painting and inherit only generic control functionality. All specific functionality must be implemented by the developer.

  2. Describe the roles of Graphics, Brush, Pen, and GraphicsPath objects in graphics rendering.

    The Graphics object represents a drawing surface and encapsulates methods that allow graphics to be rendered to that surface. A Brush is an object that is used to fill solid shapes, and a Pen is used to render lines. A GraphicsPath object represents a complex shape that can be rendered by a Graphics object.

  3. Describe the general procedure for rendering text to a drawing surface.

    You must first obtain a reference to a Graphics object. Next, create an instance of a GraphicsPath object. Use the GraphicsPath.AddString method to add text to the GraphicsPath. Then, call the Graphics.DrawPath or Graphics.FillPath to render the text.

  4. Describe the role of the LicenseProvider in control licensing.

    The LicenseProvider controls license validation and grants run-time licenses to validly licensed components. The LicenseManager.Validate method checks for an available license file and checks against the validation logic provided by the specific implementation of LicenseProvider. You specify which LicenseProvider to use by applying the LicenseProviderAttribute.

  5. Describe how to create a form or control with a nonrectangular shape.

    Set the Region property of the form or control to a Region object that contains the irregular shape. You can create a Region object from a GraphicsPath object.

Chapter 8: Advanced .NET Framework Topics

  1. Briefly describe how to use the PrintDocument component to print a document. Discuss maintaining correct line spacing and multipage documents.

    The PrintDocument class exposes the Print method, which raises the PrintPage event. Code to render printed items to the printer should be placed in the PrintPage event handler. The PrintPage event handler provides the objects required to render to the printer in an instance of the PagePrintEventArgs class. Content is rendered to the printer using the Graphics object provided by PagePrintEventArgs. You can calculate correct line spacing by dividing the height of the MarginBounds property by the height of the font you are rendering. If your document has multiple pages, you must set the PagePrintEventArgs.HasMorePages property to true, which causes the PrintPage event to fire again. Because the PrintPage event handler retains no inherent memory of how many pages have been printed, you must incorporate all logic for printing multiple pages into your event handler.

  2. Explain how to use the Begin and End methods on a Web Service to make an asynchronous method call.

    Every public Web method on a Web Service can be called either synchronously or asynchronously. To make an asynchronous call to a Web method, you call the method named Begin<webmethod>, where <webmethod> is the name of the method. This method requires a delegate to an appropriate callback method and returns a value of IAsyncResult. This value is returned as a parameter in the callback method. To retrieve the data returned by the Web method, call End<webmethod>, supplying a reference to the IAsyncResult returned by Begin<webmethod>. This will allow you to retrieve the actual data returned by the Web method.

  3. Briefly describe the five accessibility requirements of the Certified for Windows logo program.

    The five requirements are

    • Support standard system settings. This requires your application to be able to conform to system settings for colors, fonts, and other UI elements.

    • Be compatible with High Contrast mode. This requirement can be met by using only the System palette for UI colors.

    • Provide documented keyboard access for all UI features. Key points in this requirement are shortcut keys and accessible documentation.

    • Provide notification of the focus location. This requirement is handled primarily by the .NET Framework.

    • Convey no information by sound alone. This requirement can be met by providing redundant means of conveying information.

  4. Explain how to use the HelpProvider component to provide help for UI elements.

    You can provide either a HelpString or a help topic for UI elements with the HelpProvider. The HelpProvider provides HelpString, HelpKeyWord, and HelpNavigator properties for each control on the form. If no value for the HelpProvider.HelpNameSpace is set, the HelpString will be provided as help. If the HelpNameSpace is set, the HelpProvider will display the appropriate help topic as configured by the HelpKeyWord and HelpNavigator properties. Help for a particular element is displayed when the element has the focus and the F1 key is pressed.

  5. Describe how to create localized versions of a form.

    To create a localized version of a form, set the Localizable property to true. Then set the Language property to the language/region for which you want to create the localized form. Make any localization-related changes in the UI. The changed property values will automatically be stored in resource files and loaded when the CurrentUICulture is set to the appropriate CultureInfo.

  6. Explain how to convert data in legacy code page formats to the Unicode format.

    You can use the Encoding.Convert method to convert data between encoding types. This method requires instances of both encoding types and an array of bytes that represents the data to be converted. It returns an array of bytes in the target format. You can convert a string or array of chars to an array of bytes with the Encoding.GetBytes method and can convert an array of bytes back to chars with the Encoding.GetChars method.

  7. Explain the difference between Globalization and Localization.

    Globalization refers to the application of culture-specific format to existing data. Localization refers to providing new culture-specific resources and retrieving the appropriate resources based on the culture setting.

  8. Explain how to use the PrintPreviewDialog control to display a preview of a printed document before it is printed.

    You display a preview of a printed document with the PrintPreviewDialog control by first setting the PrintDocument property of the PrintPreviewDialog instance to the PrintDocument you want to preview, then by calling the PrintPreviewDialog.Show command to display the dialog box.

Chapter 9: Assemblies, Configuration, and Security

  1. Describe how to sign your assembly with a strong name. Why would you want to do this?

    To sign your assembly with a strong name, you must have access to a key file or create one with the strong name utility (sn.exe). You then specify the key file in the AssemblyInfo file and verify that the version number is correct. The assembly will be signed with a strong name when built. In addition to identifying your assembly and ensuring version identity, a strong name is required if you want to install your assembly to the Global Assembly Cache.

  2. Describe how to use code to retrieve resources at run time.

    You must first create an instance of the ResourceManager class that is associated with the assembly that contains the desired resource. You can then use the GetString method to retrieve string resources or the GetObject method to retrieve object resources.

  3. Explain how to retrieve information from the configuration file at run time. How would you store information in the configuration file at design time?

    You must first create an instance of AppSettingsReader to read the configuration file. You can then call the GetValue method to read values represented in the configuration file. To add configuration file entries, you should create <add> elements in the <appSettings> node of the configuration file. In the <add> element, you should specify a value for the entry and a key that can be used to retrieve the entry. The value can be changed between executions of the application.

  4. You are creating a solution that must be accessed by members of a group called Developers and Administrators on the local machine. Describe a plan to implement this security scheme.

    Create one PrincipalPermission that represents the Developers group and another PrincipalPermission that represents the BUILTIN\Administrators group. Then, create a third permission that represents the union of the two by calling the Union method and demand that permission.

  5. Briefly highlight the differences between imperative and declarative security as they pertain to code access security.

    Imperative security is implemented by calling methods of Permission objects in code at run time. Declarative security is configured by attaching attributes representing permissions to classes and methods. Imperative security allows a finer control over the point in execution where permissions are demanded, but declarative security is emitted into metadata, and required permissions can be discovered through the classes in the System.Reflection namespace. Additionally, you can request assembly-wide permissions using the Assembly (assembly) directive with declarative security.

  6. What is a shared assembly? How would you create one?

    An assembly is an assembly of which only a single copy is installed per machine. This copy can be shared by multiple applications. To make an assembly a shared assembly, you must first assign it a strong name, and then install it to the global assembly cache.

Chapter 10: Deploying Your Application

  1. Describe XCOPY deployment. Under what conditions is it useful? When can it not be used?

    XCOPY deployment is a simple method of deployment where the DOS command XCOPY is used to copy the application directory and any subdirectories to the target machine. You can use XCOPY deployment if your application has no dependency on shared files and requires no special actions to be taken upon deployment. If an application requires a more complex deployment or references shared assemblies, you cannot use XCOPY.

  2. You have created an application for a client who wants to distribute your application to his workforce via a network share. He wants to ensure that everyone who downloads the application will download it to the same folder. Describe a plan that would accomplish this goal.

    Create a setup project for the application. Using the User Interface Editor, provide a dialog box that allows the file directory to be set during administrative installation, but removes this box from regular installation. Use administrative installation to install the application to the network share.

  3. You have written documentation for your application and have provided it in the form of several HTML files. Describe two ways you could include this content in your setup project.

    You can include loose HTML files along with your application by either including them when you create the setup project with the Setup wizard or by adding them to the project after creation with the File System Editor.

  4. What is a native image? How do you create one?

    A native image is a precompiled version of a .NET assembly. You can create a native image of your application by using the Ngen.exe utility.

  5. What is the purpose of a bootstrapper application? When do you not need to create one?

    A bootstrapper application automatically detects if Windows Installer is installed on the target machine. If Windows Installer is not present, it installs Windows Installer before proceeding with the rest of the installation. You should create a bootstrapper application unless all of your target machines are running Windows XP (which has Microsoft Windows Installer 1.5 already installed) or have had Microsoft Installer 1.5 installed previously.

  6. Describe a general strategy for creating a setup project that terminates installation if a specific file is not already installed on the target machine.

    First, create a file search to search the file system for the specific file. Then create a launch condition to evaluate the results of the search. You can connect the launch condition to the results of the search by evaluating the value returned by the property specified in the search s Property property in the expression specified by the launch condition s Condition property.

  7. How would you ensure that all relevant registry entries were removed in the event that installation of your application failed?

    You can ensure that registry entries are removed, as well as perform any other clean-up tasks, by creating an Installer class and writing the appropriate code in the Rollback event handler. Then create a new Custom Action and set the InstallerClass, and EntryPoint properties to appropriate values.



MCAD(s)MCSD Self-Paced Training Kit(c) Developing Windows-Based Applications With Microsoft Visual Basic. Net a[.  .. ]0-316
MCAD(s)MCSD Self-Paced Training Kit(c) Developing Windows-Based Applications With Microsoft Visual Basic. Net a[. .. ]0-316
ISBN: 735619263
EAN: N/A
Year: 2003
Pages: 110

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net