
- •maranGraphics
- •CREDITS
- •ACKNOWLEDGMENTS
- •ABOUT THE AUTHORS
- •AUTHORS’ ACKNOWLEDGMENTS
- •TABLE OF CONTENTS
- •HOW TO USE THIS BOOK
- •INTRODUCTION TO C#
- •START VISUAL STUDIO .NET
- •OPEN A NEW C# PROJECT
- •OPEN A C# WEB PROJECT
- •SET JSCRIPT .NET AS THE DEFAULT SCRIPT LANGUAGE
- •EXPLORE THE CLASS VIEW WINDOW
- •VIEW THE CONTENTS WINDOW
- •GET HELP USING THE INDEX WINDOW
- •SEARCH FOR HELP
- •ADD COMPONENTS FROM THE TOOLBOX
- •ADD A TASK TO THE TASK LIST
- •CHANGE FORM PROPERTIES IN THE PROPERTIES WINDOW
- •ADD A CUSTOM TOOLBAR
- •DELETE A TOOLBAR
- •CHANGE THE VISUAL STUDIO ENVIRONMENT
- •MANAGE OPEN WINDOWS
- •OPEN A PROJECT
- •VIEW THE MAIN METHOD
- •COMBINE PROGRAM TYPES
- •ADD REFERENCE TYPES
- •ADD OPERATORS
- •INSERT ATTRIBUTES
- •ENTER CLASSES
- •ADD COMMENTS TO CODE
- •WRITE YOUR FIRST PROGRAM
- •ENTER XML DOCUMENTATION
- •ACCESS DOCUMENTATION
- •LOG A BUG REPORT
- •VIEW INFORMATION ABOUT C# BUILDING BLOCKS
- •PROGRAM CLASSES
- •ADD A CLASS
- •EMPLOY CLASS INHERITANCE
- •PROGRAM INSTANCE CONSTRUCTORS
- •INSERT DESTRUCTORS
- •PROGRAM STRUCTS
- •DISPLAY HEAP AND STACK INFORMATION
- •FIND TYPE INFORMATION
- •PROGRAM CONSTANT EXPRESSIONS
- •SPECIFY VALUE TYPES
- •PROGRAM NUMERIC TYPES
- •PROGRAM THE BOOLEAN TYPE
- •DECLARE REFERENCE TYPES
- •ENTER REFERENCE TYPE DECLARATIONS
- •CONVERT VALUE TYPES TO REFERENCE TYPES
- •PROGRAM POINTER TYPES
- •INSERT THE VOID TYPE
- •ADD INTERFACE PROPERTIES
- •ADD AN INTERFACE INDEX
- •VIEW INFORMATION ABOUT METHODS
- •ADD A METHOD
- •ADD STATIC METHODS
- •INCLUDE NON-STATIC METHODS
- •ENTER DELEGATES
- •PROGRAM EVENTS
- •ADD AN EVENT-HANDLING METHOD
- •VIEW INFORMATION ABOUT ARRAYS
- •ENTER SINGLE-DIMENSIONAL ARRAYS
- •ADD MULTIDIMENSIONAL ARRAYS
- •PROGRAM ARRAY-OF-ARRAYS
- •ITERATE THROUGH ARRAY ELEMENTS
- •SORT ARRAYS
- •SEARCH ARRAYS
- •IMPLEMENT A COLLECTIONS CLASS
- •PROGRAM STRUCTS
- •ADD AN INDEXER
- •INCLUDE ENUMERATIONS
- •CREATE STRING LITERALS AND VARIABLES
- •ASSIGN VALUES TO STRINGS
- •CONCATENATE STRINGS
- •COMPARE STRINGS
- •SEARCH FOR SUBSTRINGS
- •REPLACE CHARACTERS
- •EXTRACT SUBSTRINGS
- •CHANGE THE CHARACTER CASE
- •TRIM SPACES
- •REMOVE CHARACTERS
- •SPLIT A STRING
- •JOIN STRINGS
- •PAD STRINGS
- •VIEW INFORMATION ABOUT PROPERTIES
- •COMPARE PROPERTIES AND INDEXERS
- •PROGRAM PROPERTY ACCESSORS
- •DECLARE ABSTRACT PROPERTIES
- •INCLUDE PROPERTIES ON INTERFACES
- •VIEW INFORMATION ABOUT WINDOWS FORMS
- •ADD A WINDOWS FORM IN THE WINDOWS FORM DESIGNER
- •SET THE FORM TYPE
- •CHOOSE THE STARTUP WINDOWS FORM
- •CREATE A MODAL FORM
- •LAYOUT A FORM
- •SET A FORM LOCATION
- •CHANGE FORM PROPERTIES
- •CREATE A TRANSPARENT FORM
- •AN INTRODUCTION TO WEB FORMS AND CONTROLS
- •CREATE AN ASP.NET WEB SITE
- •CREATE A WEB FORM
- •ADD SERVER CONTROLS TO A WEB FORM
- •READ AND CHANGE PROPERTIES FROM OBJECTS ON A WEB FORM
- •USING SERVER-SIDE COMPONENTS ON WEB FORMS
- •INTRODUCING DATA ACCESS WITH ADO.NET
- •DISPLAY DATA WITH THE DATAGRID CONTROL
- •CONFIGURE THE DATAGRID CONTROL
- •INSERT DATA INTO A SQL DATABASE
- •UPDATE DATA FROM A SQL DATABASE
- •DELETE DATA FROM A SQL DATABASE
- •EXECUTE A STORED PROCEDURE IN A SQL DATABASE
- •READ XML FROM A FILE
- •SAVE XML TO A FILE
- •QUERY XML WITH XPATH
- •APPLY XSL TO XML
- •INTRODUCTION TO DISTRIBUTED APPLICATIONS
- •CREATE AN APPLICATION WITH PRIVATE ASSEMBLIES
- •CREATE AN APPLICATION WITH SHARED ASSEMBLIES
- •VERSION A SHARED ASSEMBLY
- •CONFIGURE A CLIENT FOR A VERSIONED ASSEMBLY
- •CREATE A WEB SERVICE
- •USING A WEB SERVICE
- •INTRODUCTION TO EXCEPTION HANDLING
- •THROWING AN EXCEPTION
- •HANDLING EXCEPTIONS WITH THE CATCH BLOCK
- •USING THE FINALLY BLOCK
- •WRITE ERRORS TO THE APPLICATION LOG
- •BASIC EXAMPLES
- •WHAT’S ON THE CD-ROM
- •USING THE E-VERSION OF THIS BOOK
- •INDEX
- •Symbols & Numbers

C#
DECLARE ABSTRACT PROPERTIES
bstract properties are properties that you can place in Aabstract classes. If you remember, an abstract class
acts as the base class for inheriting classes. The same is true for inheriting and base interfaces. So, abstract properties are base class properties so properties in inheriting classes or interfaces can access them.
Like a class, you have to declare an abstract property by using the abstract keyword. An abstract property automatically comes with the virtual modifier just as a class does. The virtual modifier tells your program to check for overriding properties in inheriting classes automatically.
An abstract property does not declare any accessors. Instead, the abstract property provides only basic
information about properties that properties in inheriting classes can use. When the inheriting property combines its accessors with the abstract property information, the program creates a complete property that you can then use for computing property values.
Because the abstract property does not include any specific information — it merely “sets the table” for an inheriting property to perform its duty — the only text in the body of an abstract property is a semicolon after the get and set accessors. If you try to enter any other information, the MDE window will report the error and your program will not compile.
DECLARE ABSTRACT PROPERTIES
Start page appears. ■ The New Project window
appears.
New Project.
‹ Click the Console Application icon in the Templates pane.
› Type a name for the file.
ˇ Click OK.

ACCESSING PROPERTIES 9
As with an abstract class or interface, there are restrictions that you must be aware of.
One restriction is that you cannot add any modifiers to an abstract property because C# automatically designates the abstract property as virtual. That means that you cannot add any of the other modifiers including static, override, or new. That also includes the virtual modifier. As long as you enter abstract as the property modifier and that abstract property resides in an abstract class or interface, you will have no problems.
Another restriction is that you cannot use the base keyword for retrieving property information from an abstract property. For example, if you declare an abstract property with an integer value of A and try to enter return base.A for returning the value of A, you will not be able to do so. The MDE window will catch your mistake if you attempt this maneuver.
Task List - 4 Build Error tasks shown (filtered)
|
Á Type the abstract property |
‡ Run the program by |
|
||
code. |
pressing F5. |
|
|
|
■ Because the abstract |
|
|
property cannot take a body, |
|
|
the MDE window registers the |
|
|
error. |
° Save the program as the filename.
193

C#
INCLUDE PROPERTIES ON INTERFACES
ou can declare properties not only on classes but also Yon interfaces. When you have classes that process an
interface, those classes take the properties from those interfaces for further processing. Properties on an interface have a slightly different form than properties on a class.
You declare a property on an interface by using the new keyword. You can preface the keyword with attributes that C# uses to denote certain conditions; for example, you can tell your program that the property is obsolete and is no longer used.
After the new keyword, you can add the access type, which is the same as it is on class properties, classes, methods, and
other C# components. After you add the access type, you can enter the name of your interface property.
The interface accessors appear next enclosed in curly braces ({}). Neither the set and get accessors contain any other information in their bodies except for a semicolon. Like an abstract property, the interface property acquires information from other component properties (such as the one in a class) instead of processing properties itself. The get and set accessors serve only to determine whether the property is read-only (get), write-only (set), or readwrite (get and set).
INCLUDE PROPERTIES ON INTERFACES
Project window
Console in the
.
for the file.
Class View - In...
Point
Á Type the Point interface code.
‡ Click the Class View tab.
° Click the plus sign next to the Method name.
· Click the plus sign next to the {} Method name.
‚ Right-click Interface1.
— Click Add.
± Click Add Property.

ACCESSING PROPERTIES 9
When a class or struct implements an interface, you can write your class or struct property to declare explicit interface member implementations. This is useful if you need to have an internal interface for performing tasks without passing it on to other parts of your program (and perhaps as output).
TYPE THIS:
interface Clones
{
object Clone();
}
interface Compare
{
int CompareTo(object template);
}
class Assembly: Clones, Compare
{
int Compare.CompareTo(object template);
}
RESULT:
The above example declares Compare. CompareTo as an explicit interface member implementation.
■ The C# Interface Property Wizard window appears.
¡ Click to select the property type from the drop-down list.
™ Type the property name in the property name field.
■ Leave the accessor get/set radio button selected.
£ Type a property comment in the Comment field.
¢ Click Finish.
■ The interface property |
∞ Save the program as the |
code appears in the parent |
filename. |
window. |
|
195