- •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#
LOG A BUG REPORT
It is inevitable that a product as sophisticated as Visual Studio .NET will have a few bugs in it. Microsoft wants your help in identifying bugs you have run into so the
Visual Studio .NET team at Microsoft can fix your reported problem as quickly as possible. Microsoft makes it easy for you to send issues to Microsoft directly in the Microsoft Development Environment, MDE, window.
You log into the Visual Studio .NET Web site with your username and password. If you do not have a username or password, you can create one from the Web site. When you create a username and password, you will also have to enter your contact information that includes your name, mailing address, e-mail address, and telephone number.
After you log on successfully, you can read up on Visual Studio .NET news and information from the Visual Studio
.NET site, and from here you can also log bug reports. After you enter a bug report, the Web site forwards the report to the appropriate personnel on the Visual Studio .NET team.
If the Visual Studio .NET team needs more information from you to replicate or fix the problem, they will contact you by e-mail using the contact information you entered when you created your username and password.
LOG A BUG REPORT
.NET issue
■ The Start page appears in the parent window.
¤ Click the Report a Visual Studio .NET issue link.
■ The Login page appears in the parent window.
Note: If you have a dial-up Internet connection, your dial-up connection window will appear so you can dial your Internet service provider. If you cannot connect to the Internet, the parent window displays an action cancelled message stating that Internet Explorer was unable to connect.
‹ Enter your login ID and password.
Note: If you do not have a login ID or password, sign up by clicking the Register Now link.
› Click Submit.
WORKING WITH VISUAL C# BASICS 3
It is easy to forget passwords, because you can have different passwords for each service, program, or operating system that requires a password. You should keep your passwords in a safe place, never on a network, so you can refer to them in case you forget them.
If you forget your password into the Visual Studio .NET site, you can click the I forgot my password link in the Login page. You will have to enter your user ID name and your e-mail address so Microsoft can e-mail you your password. If you forget your user ID name then you will have to open a new account with a different username so you can log on.
You can submit feedback directly to the Visual Studio .NET team at Microsoft without entering the Visual Studio .NET site. The Login page has a Feedback link at the upper right-hand corner of the site. When you click this link, a blank e-mail message to the Visual Studio .NET team e-mail address will appear so you can send the team an e-mail with your comments, suggestions, and/or problems.
your product feedback
■ The Visual Studio .NET welcome page appears.
Note: Before you see the Welcome page, you may see a Security Alert dialog box informing you that you will be directed to a non-secure page. Click the Yes button in the box if it appears.
ˇ Enter a bug report by clicking the your product feedback link.
340056
eric@eebutow.com
■ The bug report screen appears so you can give technical support detailed information about your problem.
63
C#
VIEW INFORMATION ABOUT C# BUILDING BLOCKS
# contains three different types of building blocks Cthat define variables and functionality. You combine
these building blocks — methods, classes, and structures — together to form a functioning program.
A class is the smallest building block, and it acts like a box for you to keep certain classes of elements such as the ages of your cats. You can also declare classes as base classes where a class can inherit characteristics from a base class. For example, you can have a base class of cats’ names and have inheritor classes that contain more specific information such as fur color.
A structure is a value type. Unlike a class, which contains references to data in your program, a structure contains the data to which the classes refer. You can create structures using the struct keyword that you will learn about later in this chapter.
A module, the largest building block, is a portable executable file that can contain structures and classes. Modules have .exe (executable) or .dll (Dynamic Link
Library) extensions; you can use modules to test various portions of your program before you integrate them and to integrate with other Windows programs that will reference the same DLL file.
VIEW INFORMATION ABOUT C# BUILDING BLOCKS
Index... |
Ctrl+Alt+F2 |
⁄ Click Start Programs |
|
¤ Click Help. |
|
|
|||
Microsoft Visual Studio .NET |
|
|
‹ Click Index. |
7.0 Microsoft Visual Studio |
|
||
.NET 7.0. |
|
|
|
■ The Start page appears. |
|
|
|
■ The Index menu appears.
Note: Close the Properties window by clicking to the right of the Properties title bar.
Visual C#
› Type modules in the Look for field.
ˇ Click to select Visual C# from the Filtered by drop-down list.
PROGRAMMING C# BUILDING BLOCKS 4
You can create a module with the class name Module so your program knows the module will integrate with other parts of a program with a namespace such as a class. This ensures that your module and a class in your program work together.
If you want to create modules as separate programs, you can give each one a separate namespace name, or if you want to have the modules integrated, you can give several modules the same namespace name.
Classes help your program run more quickly. A class has the extra advantage of being a reference type — you can pass along a class that contains data instead of passing the data itself. Structs have the advantage of requiring less memory because moving a struct means that the program does not have to keep referencing data and using memory for that purpose.
Á Click compared to classes in the topics list.
■ The Ways to Implement Component Functionality page appears in the parent window.
‡ Scroll down the page until |
■ The comparison table |
you reach the comparison |
compares the different |
table. |
components. |
65