Microsoft Visual C# .NET Step by Step 2003

( 6 )

Overview

Build your dexterity with Microsoft Visual C#—and begin writing Microsoft .NET–connected applications—one step at a time! This practical, hands-on tutorial expertly guides you through the fundamentals—from learning Visual C# syntax to writing and running your first components, Web services, and applications. Work at your own pace through easy-to-follow lessons and hands-on exercises to teach yourself essential techniques. And stay ahead of the curve by working with real-world ...

See more details below
Available through our Marketplace sellers.
Other sellers (Paperback)
  • All (52) from $1.99   
  • New (12) from $5.04   
  • Used (40) from $1.99   
Close
Sort by
Page 1 of 2
Showing 1 – 9 of 12 (2 pages)
Note: Marketplace items are not eligible for any BN.com coupons and promotions
$5.04
Seller since 2009

Feedback rating:

(2338)

Condition:

New — never opened or used in original packaging.

Like New — packaging may have been opened. A "Like New" item is suitable to give as a gift.

Very Good — may have minor signs of wear on packaging but item works perfectly and has no damage.

Good — item is in good condition but packaging may have signs of shelf wear/aging or torn packaging. All specific defects should be noted in the Comments section associated with each item.

Acceptable — item is in working order but may show signs of wear such as scratches or torn packaging. All specific defects should be noted in the Comments section associated with each item.

Used — An item that has been opened and may show signs of wear. All specific defects should be noted in the Comments section associated with each item.

Refurbished — A used item that has been renewed or updated and verified to be in proper working condition. Not necessarily completed by the original manufacturer.

New
2003-04-16 Paperback New 0735619093 Ships Within 24 Hours. Tracking Number available for all USA orders. Excellent Customer Service. Upto 15 Days 100% Money Back Gurantee. Try ... Our Fast! ! ! ! Shipping With Tracking Number. Read more Show Less

Ships from: Bensalem, PA

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
  • Express, 48 States
  • Express (AK, HI)
$5.99
Seller since 2008

Feedback rating:

(1752)

Condition: New
2003 Paperback New Ships out next day, click expedited for faster shipping.

Ships from: cadiz, KY

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
  • Express, 48 States
  • Express (AK, HI)
$12.46
Seller since 2010

Feedback rating:

(674)

Condition: New
PAPERBACK New 0735619093! ! ! ! BEST PRICES WITH A SERVICE YOU CAN RELY! ! !

Ships from: Philadelphia, PA

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
  • Express, 48 States
  • Express (AK, HI)
$12.46
Seller since 2010

Feedback rating:

(901)

Condition: New
PAPERBACK New 0735619093 Friendly Return Policy. A+++ Customer Service!

Ships from: Philadelphia, PA

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
  • Express, 48 States
  • Express (AK, HI)
$12.46
Seller since 2013

Feedback rating:

(389)

Condition: New
PAPERBACK New 0735619093! ! KNOWLEDGE IS POWER! ! ENJOY OUR BEST PRICES! ! ! Ships Fast. All standard orders delivered within 5 to 12 business days.

Ships from: Southampton, PA

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
  • Express, 48 States
  • Express (AK, HI)
$12.46
Seller since 2011

Feedback rating:

(710)

Condition: New
PAPERBACK New 0735619093 SERVING OUR CUSTOMERS WITH BEST PRICES. FROM A COMPANY YOU TRUST, HUGE SELECTION. RELIABLE CUSTOMER SERVICE! ! HASSLE FREE RETURN POLICY, SATISFACTION ... GURANTEED**** Read more Show Less

Ships from: Philadelphia, PA

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
  • Express, 48 States
  • Express (AK, HI)
$12.46
Seller since 2014

Feedback rating:

(265)

Condition: New
PAPERBACK New 0735619093 XCITING PRICES JUST FOR YOU. Ships within 24 hours. Best customer service. 100% money back return policy.

Ships from: Bensalem, PA

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
  • Express, 48 States
  • Express (AK, HI)
$12.50
Seller since 2011

Feedback rating:

(3)

Condition: New
New Condition not used

Ships from: Murphy, TX

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
$20.80
Seller since 2008

Feedback rating:

(169)

Condition: New
0735619093 BRAND NEW NEVER USED IN STOCK 125,000+ HAPPY CUSTOMERS SHIP EVERY DAY WITH FREE TRACKING NUMBER

Ships from: fallbrook, CA

Usually ships in 1-2 business days

  • Standard, 48 States
  • Standard (AK, HI)
Page 1 of 2
Showing 1 – 9 of 12 (2 pages)
Close
Sort by
Sending request ...

Overview

Build your dexterity with Microsoft Visual C#—and begin writing Microsoft .NET–connected applications—one step at a time! This practical, hands-on tutorial expertly guides you through the fundamentals—from learning Visual C# syntax to writing and running your first components, Web services, and applications. Work at your own pace through easy-to-follow lessons and hands-on exercises to teach yourself essential techniques. And stay ahead of the curve by working with real-world examples and best practices for Visual C# development.

Discover how to:

  • Declare variables, define methods, and construct statements
  • Handle and trap exceptions
  • Use object-oriented techniques, such as inheritance and encapsulation
  • Manage resources and use the garbage collector
  • Build components, including properties, indexers, and events
  • Define operators to enhance class usability
  • Create GUI components and user controls
  • Access data sources using Microsoft ADO.NET
  • Write and manipulate XML documents
  • Construct Web Forms that display large volumes of data
  • Validate user input with Microsoft ASP.NET controls
  • Write, test, and deploy Web services

CD features:

  • Code examples in Visual C# .NET 2003
  • All the book’s practice files
  • Fully searchable eBook

For customers who purchase an ebook version of this title, instructions for downloading the CD files can be found in the ebook.

Read More Show Less

Product Details

  • ISBN-13: 9780735619098
  • Publisher: Microsoft Press
  • Publication date: 3/26/2003
  • Series: Microsoft Step by Step Series
  • Edition description: BK&CD-ROM
  • Edition number: 2
  • Pages: 672
  • Product dimensions: 7.32 (w) x 9.10 (h) x 1.70 (d)

Meet the Author

Jon Jagger is an independent software trainer, designer, and consultant specializing in Visual C# .NET, C++, Java, C, OO, patterns, design, and general programming. His work on this book also was done through Content Master Ltd. Jon is a U.K. C++ standards panel member and a regular contributor to the ACCU Overload journal. His interests include training excellence, design, simplicity, problem solving, and Monty Python (which he says is required knowledge for all software developers). Jon, his wife, Natalie, and their three small children (Ellie, Penny, and Patrick) live in a delightful 104-year-old house overlooking a seven-acre field of barley in a village called Trull (population 300). You can send him an e-mail message at jon@jaggersoft.com.

Read More Show Less

Table of Contents

Acknowledgments
Introduction
Pt. 1 Introducing Microsoft Visual C# and Visual Studio .NET
Ch. 1 Welcome to C# 3
Ch. 2 Working with Variables, Operators, and Expressions 27
Ch. 3 Writing Methods and Applying Scope 43
Ch. 4 Using Decision Statements 59
Ch. 5 Using Iteration Statements 73
Ch. 6 Managing Errors and Exceptions 93
Pt. 2 Understanding the C# Language
Ch. 7 Creating and Managing Classes and Objects 115
Ch. 8 Understanding Values and References 135
Ch. 9 Creating Value Types with Enumerations and Structs 153
Ch. 10 Using Arrays and Collections 171
Ch. 11 Understanding Parameter Arrays 193
Ch. 12 Working with Inheritance 207
Ch. 13 Using Garbage Collection and Resource Management 231
Pt. 3 Creating Components
Ch. 14 Implementing Properties to Access Attributes 249
Ch. 15 Using Indexers 265
Ch. 16 Delegates and Events 281
Ch. 17 Operator Overloading 301
Pt. 4 Working with Windows Applications
Ch. 18 Introducing Windows Forms 319
Ch. 19 Working with Menus 341
Ch. 20 Performing Validation 357
Ch. 21 Using Complex Controls 371
Ch. 22 Using the MDI, Windows, and Dialog Boxes 397
Ch. 23 Creating GUI Components 415
Pt. 5 Managing Data
Ch. 24 Using a Database 437
Ch. 25 Working with Data Binding and DataSets 459
Ch. 26 Handling XML 479
Pt. 6 Building Web Applications
Ch. 27 Introducing ASP.NET 501
Ch. 28 Understanding Validation Controls 525
Ch. 29 Accessing Data with Web Forms 535
Ch. 30 Building ASP.NET Applications 559
Ch. 31 Building an XML Web Service 579
Ch. 32 Consuming a Web Service 597
Read More Show Less

First Chapter

  • Declaring Methods
    • Specifying the Method Declaration Syntax
    • Writing return Statements
  • Calling Methods
    • Specifying the Method Call Syntax
  • Understanding Scope
    • Creating Local Scope with a Method
    • Creating Class Scope with a Class
    • Overloading Identifiers
  • Writing and Calling Methods
  • Chapter 3 Quick Reference

Chapter 3 Writing Methods and Applying Scope
In this chapter, you will learn how to:
  • Create and call methods.
  • Pass information to a method.
  • Return information from a method.
  • Use the Microsoft Visual Studio .NET integrated debugger to step in and out of methods as they run.

In Chapter 2, you learned how to declare variables, how to create expressions using operators, and how precedence and associativity control expressions containing multiple operators. In this chapter, you’ll learn all about methods. You’ll also learn how to use arguments and parameters to pass information to a method and how to return information from a method using return statements. Finally, you’ll see how to step in and out of methods using the Microsoft Visual Studio .NET integrated debugger. This information is useful when you need to trace the execution of your methods because they do not work quite as you expected.

Declaring Methods

A method is a named sequence of statements. Each method has a name and a body. The method body contains the actual statements to be run when the method is called. The method name should be a meaningful identifier that indicates the overall purpose of the method (CalculateIncomeTax, for example). Most methods can be given some data, which they process, and can return information, which is usually the result of the processing. Methods are a fundamental and powerful mechanism.

Specifying the Method Declaration Syntax

The syntax of a Microsoft Visual C# method is as follows:

returnType  methodName parameterList 

    // method body statements go here 
}

  • The returnType is the name of a type and specifies what kind of information the method returns. This can be the name of any type, such as int or string. If you’re writing a method that does not return a value, you must use the keyword void in place of the return type.
  • The methodName is the name used to call the method. Method names must follow the same identifier rules as variable names. For example, addValues is a valid method name, whereas add$Values is not valid. For now, you should use camelCase for method names, and you should make method names descriptive—start with a verb, such as displayCustomer.
  • The parameterList is optional and describes the types and names of the information that the method accepts. You write the parameters between the left and right parentheses as though you’re declaring variables: name of the type, followed by the name of the parameter. If the method you’re writing has two or more parameters, you must separate them with commas.
  • The method body statements are the lines of code that are run when the method is called. They are enclosed in an opening curly brace ({) and a closing curly brace (}).

IMPORTANT:
C, C++, and Microsoft Visual Basic programmers should note that C# does not support global methods. You must write all your methods inside a class or your code will not compile.

Here’s the definition of a method called addValues that returns an int and has two int parameters called lhs and rhs (short for left-hand side and right-hand side, respectively):

int addValues(int lhs, int rhs) 

    // ...
    // method body statements go here 
    // ...
}

Here’s the definition of a method called showResult that does not return a value and has a single int parameter called answer:

void showResult(int answer)
{
    // ...
}

Notice that you use the keyword void to indicate that the method does not return anything.


IMPORTANT:
Visual Basic programmers should notice that C# does not use different keywords to distinguish between a method that returns a value (a function) and a method that does not return a value (a procedure or subroutine). You must always specify either a return type or void.

Writing return Statements

If you want your method to return information (in other words, its return type is not void), you must write a return statement inside the method. You do this using the keyword return followed by an expression that calculates the returned value and a semicolon. The type of expression must be the same as the type specified by the function. In other words, if a function returns an int, the return statement must return an int; otherwise your program will not compile. Here is an example:

int addValues(int lhs, int rhs) 

    // ... 
    return lhs + rhs;
}

The return statement should be at the end of your method because it causes the method to finish. Any statements after the return statement will not be executed (though the compiler will warn you about this problem if you put statements after the return statement).

If you don’t want your method to return information (its return type is void), you can use a variation of the return statement to cause an immediate exit from the method. You write the keyword return, immediately followed by a semicolon. For example:

(Code Unavailable)

If your method does not return anything, you can also omit the return statement because the method will finish automatically when execution arrives at the closing curly brace at the end of the method. Although this practice is common, it is not always considered good style. Methods that return a value must contain a return statement.

In the following exercise, you will examine another version of the MathsOperators application from Chapter 2. This version has been improved by the careful use of some small methods.


TIP:
There is no minimum size for a method. If a method helps to avoid repetition and makes your program easier to understand, the method is useful regardless of how small it is.
Examine method definitions:
  1. Start Visual Studio .NET.
  2. On the File menu, point to Open, and then click Project. The Open Project dialog box opens.
  3. In the \Microsoft Press\Visual C# Step by Step\Chapter 3\Methods folder in your My Documents folder, open the Methods project. The Methods project opens in the programming environment.
  4. On the Debug menu, click Start. Visual Studio .NET builds and runs the application.
  5. Practice using the application for a while, and then click Quit. You return to the Visual Studio .NET programming environment.
  6. In the Code pane, click the Form1.cs tab. (Right-click on the form and choose View Code if the Form1.cs tab isn’t visible. If the form isn’t visible, right-click Form1.cs in the Solution Explorer and choose View Code.) The Code View of Form1.cs opens in the Code pane.
  7. In the Code pane, locate the addValues method. Your Code pane now looks like this:
  8. (Image unavailable)

    The addValues method contains two statements. The first statement assigns to the expression.Text property the string created by concatenating three strings. The second statement adds the values of the lhs and rhs int variables together using the + operator and returns the result of this addition. Notice that adding two int values together creates another int value and that the return type of addValues is int.

  9. In the Code pane, locate the showResult method.
  10. The showResult method contains one statement that assigns to the result.Text property a string representation of the answer parameter.


Calling Methods

Methods exist to be called! You call a method by name to ask it to perform its task. If the method requires information (as specified by its parameters), you must supply the information as requested. If the method returns information (as specified by its return type), you should arrange to catch this information somehow.

Specifying the Method Call Syntax

The syntax of a C# method call is as follows:

methodName argumentList )

  • The methodName must exactly match the name of the method you’re calling. Remember, C# is a case-sensitive language.
  • The argumentList supplies the optional information that the method accepts. You must supply an argument for each parameter, and the value of each argument must be compatible with the type of its corresponding parameter. If the method you’re calling has two or more parameters, you must separate the arguments with commas.

IMPORTANT:
You must write the parentheses in every method call, even when calling a method with no arguments.

Here is the addValues method:

int addValues(int lhs, int rhs) 

    // ... 
}

The addValues method has two int parameters, so you must call it with two comma-separated int arguments:

addValues(39, 3)     // okay

If you try to call addValues in some other way, you will probably not succeed:

addValues            // compile time error, no parentheses
addValues()          // compile time error, not enough arguments
addValues(39)        // compile time error, not enough arguments
addValues("39", "3") // compile time error, wrong types

The addValues method returns an int value. This int value can be used wherever an int value can be used. Consider this example:

result = addValues(39, 3);    // on right hand side of an assignment
showResult(addValues(39, 3)); // as argument to another method call

The following exercise continues using the MathsOperators application that was introduced in Chapter 2. This time you will examine some method calls.


Examine method calls:
  1. In the \Microsoft Press\Visual C# Step by Step\Chapter 3\Methods folder in your My Documents folder, open the Methods project. (This project is already open in Visual Studio .NET if you’re continuing from the previous exercise.)
  2. In the Solution Explorer, right-click the Form1.cs entry, and then click View Code.
  3. Locate the calculate_Click method. Look at the fourth statement of this method. It is as follows:
  4. showResult(addValues(lhs, rhs));

  5. In the Code pane, find the showResult method. The only statement of this method is this:
  6. result.Text = answer.ToString();

    Notice that the ToString method call uses parentheses even though there are no arguments.


TIP:
You can call methods belonging to other objects by prefixing the method with the name of the object. In the previous example, the expression answer.ToString() calls the method named ToString belonging to the object called answer.

Understanding Scope

You have seen that you can create a variable inside a method. The variable is created at the statement that defines it, and other statements in the same method that come afterwards can use the variable. In other words, a variable can be used only in certain places after it has been created. Once the method has finished, the variable disappears completely.

If an identifier can be used at a particular location in a program, the identifier is said to be in scope at that location. To put it another way, the scope of an identifier is simply the region of the program in which that identifier is usable. Scope applies to methods as well as variables. The scope of an identifier is linked to the location of the declaration that introduces the identifier into the program, as you’ll now learn.

Creating Local Scope with a Method

The left and right curly braces that form the body of a method create a scope. Any variables you declare inside the body of a method are scoped to that method. These variables are called local variables because they are local to the method in which they are declared; they are not in scope in any other method. This arrangement means that you cannot use local variables to share information between methods. Consider this example:

(Code Unavailable)

Creating Class Scope with a Class

The left and right curly braces that form the body of a class also create a scope. Any "variables" you declare inside the body of a class (but not inside a method) are scoped to that class. As we saw in Chapter 2, the proper C# name for these variables is fields. In contrast to local variables, you can use fields to share information between methods. Here is an example:

(Code Unavailable)


NOTE:
In a method, you must declare a variable before you can use it. Fields are a little different. A method can use a field before the field is defined—the compiler sorts out the details for you!

Overloading Identifiers

If two identifiers have the same name and are declared in the same scope, you say that they are overloaded, that they overload each other. Most of the time an overloaded identifier is a bug that gets trapped as a compile-time error. For example, if you declare two local variables with the same name in the same method, you’ll get a compile-time error. Similarly, if you declare two fields with the same name in the same class or two identical methods in the same class, you’ll also get a compile-time error. This fact must seem hardly worth mentioning given that everything so far has turned out to be a compile-time error. Well, there is a way that you can overload an identifier, and that way is both useful and important.

You are allowed to overload a method, but only when the two methods have different parameters; that is, they have the same name but a different number of parameters, or the types of the parameters differ. This capability is allowed so that, when you call a method, you supply comma-separated arguments and the number and type of the arguments is used to select one of the overloaded methods.

The WriteLine method of the Console class is a good example of overloading. If you want to write a string to the console, you pass a string argument to WriteLine, and WriteLine(string s) is automatically called. If you want to write an int to the console, you pass an int argument to WriteLine and WriteLine(int i) is automatically called. Once again, the compiler sorts out the details for you.

At compile time, the compiler looks at the types of the arguments you are passing in and then calls the version of the named method that has a matching set of parameters. Here is an example:

static void Main()
{
    Console.WriteLine("The answer is ");
    Console.WriteLine(42);
}

Whereas you can overload the parameters of a method, you can’t overload the return type of a method. In other words, you can’t declare two methods with the same name that differ only in their return type. (The compiler is clever, but not that clever.)


TIP:
C++ and Visual Basic programmers should notice that C# does not support default arguments. However, you can mimic default arguments using overloaded methods.

Writing and Calling Methods

In the following exercises, you’ll use the C# Method Wizard to help you write some methods that calculate how much a consultant would charge for a given number of consultancy days at a fixed daily rate. Next, you’ll run these methods in a console application to get a feel for the program. Finally, you’ll use the Visual Studio .NET debugger to step in and out of the method calls as they run.


Write a method using the C# Method Wizard:
  1. On the File menu, point to Open, and then click Project. The Open Project dialog box opens.
  2. In the \Microsoft Press\Visual C# Step by Step\Chapter 3\DailyRate folder in your My Documents folder, open the DailyRate project. The DailyRate project opens.
  3. (Image unavailable)

  4. On the View menu, click Class View. The Class View window appears.
  5. In the Class View window, click the + sign to the left of DailyRate. The DailyRate namespace appears.
  6. In the Class View window, click the + sign to the left of { } DailyRate. The Class1 class appears.
  7. (Image unavailable)

  8. In the Class View window, right-click Class1. A menu appears.
  9. On the menu, point to Add, and then click Add Method. The C# Method Wizard opens.
  10. (Image unavailable)

  11. Select double from the Return Type list.
  12. Type readDouble in the Method Name box.
  13. Select string from the Parameter Type list.
  14. Type prompt in the Parameter Name box, and then click Add.
  15. Click Finish. The C# Method Wizard closes and the following method declaration appears in the Code pane:
  16. public double readDouble(string prompt)
    {
        return 0;
    }

  17. Delete the return statement and enter the following statements inside the readDouble method:
  18. Console.Write(prompt);
    string line = Console.ReadLine();
    return double.Parse(line);

  19. On the Build menu, click Build Solution.
  20. Verify that the readDouble method you have created compiles without error.

Write the remaining methods:
  1. Use the C# Method Wizard to create another method using the following settings:
  2. Control name Setting
    Return type int
    Method name readInt
    Parameter type string
    Parameter name prompt
  3. Click Finish. The C# Method Wizard closes and the following method declaration appears in the Code pane:
  4. public int readInt(string prompt)
    {
        return 0;
    }

  5. Delete the return statement. Type the following statements inside the readInt method:
  6. Console.Write(prompt);
    string line = Console.ReadLine();
    return int.Parse(line);

  7. On the Build menu, click Build Solution.
  8. As before, verify that the readInt method you have declared compiles without error.
  9. Use the C# Method Wizard to create another method using the following settings. (You will need to click Add after creating each parameter.)
  10. Control name Setting
    Return type double
    Method name calculateFee
    Parameter type double
    Parameter name dailyRate
    Parameter type int
    Parameter name noOfDays
  11. Click Finish. The C# Method Wizard closes and the following method declaration appears in the Code pane:
  12. public double calculateFee(double dailyRate, int noOfDays)
    {
        return 0;
    }

  13. Change the return statement to calculate the fee, as shown here:
  14. return dailyRate * noOfDays;

  15. On the Build menu, click Build Solution.
  16. Verify that the calculateFee method you have declared compiles without error.
  17. Use the C# Method Wizard to create another method using the following settings:
  18. Control name Setting
    Return type void
    Method name writeFee
    Parameter type double
    Parameter name fee
  19. Click Finish. The C# Method Wizard closes and the following method declaration appears in the Code pane:
  20. public void writeFee(double fee)
    {

    }

  21. Type the following statements inside the writeFee method:
  22. Console.WriteLine("The consultant’s fee is: {0}", fee * 1.1);

  23. On the Build menu, click Build Solution.
  24. Verify that the writeFee method you have declared compiles without error.

TIP:
If you feel sufficiently comfortable with the syntax, you can also write methods by typing them directly in the Code pane; you do not always have to use the C# Method Wizard.
Call the methods and run the program:
  1. In the Code pane, locate the run method.
  2. Type the following statements inside the run method:
  3. double dailyRate = readDouble("Enter your daily rate: ");
    int noOfDays = readInt("Enter the number of days: ");
    writeFee(calculateFee(dailyRate, noOfDays));

  4. On the Debug menu, click Start Without Debugging. Visual Studio .NET builds the program and then runs it. A console window appears.
  5. At the Enter Your Daily Rate prompt, type 525 and then press Enter.
  6. At the Enter The Number Of Days prompt, type 17 and then press Enter. The program writes the following message to the console window:
  7. The consultant’s fee is: 9817.5
    Press any key to continue

  8. Press any key to return control to the Visual Studio .NET programming environment.

In the final exercise, you’ll use the Visual Studio .NET debugger to run your program in slow motion. You’ll see when each method is called (this action is referred to as stepping into the method) and then see each return statement transfer control back to the caller (also known as stepping out of the method).

While you are stepping in and out of methods, you’ll use the tools on the Debug toolbar. The Debug toolbar should appear automatically when you debug a program. If the toolbar does not appear, you can display it by pointing to Toolbars on the View menu and then clicking Debug.


Step through the methods using the Visual Studio .NET debugger:
  1. In the Code pane, find the run method.
  2. Move the mouse pointer to the first statement in the run method. The first statement in the run method is as follows:
  3. double dailyRate = readDouble("Enter your daily rate: ");

    Right-click anywhere on this line.

  4. On the pop-up menu, click Run To Cursor. The program runs to the statement underneath the cursor.
  5. A yellow arrow in the left margin of the Code pane indicates which is the current statement. The current statement is also highlighted with a yellow background.

  6. On the View menu, point to Toolbars, and then click Debug (if it is not already selected). The Debug toolbar opens.
  7. The Debug toolbar might appear docked with the other toolbars. If you cannot see the toolbar, try deselecting it using the Toolbars command on the View menu, and notice which buttons disappear. Then display the toolbar again.


    TIP:
    To make the Debug toolbar appear in its own window, click the handle on the left edge of the toolbar and drag it over the Code pane.
  8. On the Debug toolbar, click Step Into. The yellow cursor jumps to the first statement of the readDouble method.
  9. On the Debug toolbar, click Step Out. The program displays the Enter Your Daily Rate prompt in a console window.
  10. Type 525 in the console window, and then press Enter. Control returns to the Visual Studio .NET programming environment. (You might need to click on the Visual Studio .NET window to bring it to the foreground.) The yellow cursor has stepped out of the readDouble method and is now back at the first statement of the run method.
  11. On the Debug toolbar, click Step Into. The yellow cursor moves to the second statement in the run method:
  12. int noOfDays = readInt("Enter the number of days: ");

  13. On the Debug toolbar, click Step Into. The yellow cursor jumps into the first statement of the readInt method.
  14. On the Debug toolbar, click Step Out. The program displays the Enter The Number Of Days prompt in the console window.
  15. Type 17 and then press Enter. Control returns to the Visual Studio .NET programming environment. The yellow cursor has stepped out of the readInt method and is now back at the second statement of the run method.
  16. On the Debug toolbar, click Step Into. The yellow cursor moves to the third statement of the run method:
  17. writeFee(calculateFee(dailyRate, noOfDays));

  18. On the Debug toolbar, click Step Into. The yellow cursor jumps into the first statement of the calculateFee method.
  19. On the Debug toolbar, click Step Out. The yellow cursor jumps back to the third statement of the run method.
  20. On the Debug toolbar, click Step Into. The yellow cursor jumps into the first statement of the writeFee method.
  21. On the Debug toolbar, click Step Out. The yellow cursor jumps to the closing curly brace at the end of the run method. In the console window, the program displays the consultant’s fee, as shown in the following illustration.
  22. (Image unavailable)

  23. On the Debug toolbar, click Stop Debugging
  24. On the Debug toolbar, click Close.

Congratulations! You’ve successfully written and called methods and used the Visual Studio .NET debugger to step in and out of methods as they run.


TIP:
When debugging an application, you can press F11 instead of clicking the Step Into button on the Debug toolbar.

If you want to continue to the next chapter

  • Keep Visual Studio .NET running and turn to Chapter 4.

If you want to exit Visual Studio .NET now

  • On the File menu, click Exit. If you see a Save dialog box, click Yes.

Chapter 3 Quick Reference

To Do this Button
Declare a method Write the method inside a class. For example:

(Code Unavailable)

 
Return a value from inside a method Write a return statement inside the method. For example:

return lhs + rhs;

 
Return from a method before the end of the method Write a return statement inside the method. For example:

return;

 
Call a method Write the name of the method, together with any arguments between parentheses. For example:

addValues(39, 3);

 
Use the C# Method Wizard to help you write a method In Class View, right-click the name of the class. On the pop-up menu, point to Add, and then click Add Method.  
Display the Debug toolbar On the View menu, point to Toolbars, and then click Debug.  
Step into a method On the Debug toolbar, click Step Into.

Or

On the Debug menu, click Step Into.

(Image unavailable)
Step out of a method On the Debug toolbar, click Step Out.

Or

On the Debug menu, click Step Out.

(Image unavailable)
Read More Show Less

Customer Reviews

Average Rating 2.5
( 6 )
Rating Distribution

5 Star

(1)

4 Star

(1)

3 Star

(0)

2 Star

(2)

1 Star

(2)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 6 Customer Reviews
  • Anonymous

    Posted November 22, 2005

    Excellent for those with no prior experience in Visual C# .NET

    Wow, having read the other reviews, I have to wonder if we're talking about the same book! It's true that one needs to have Visual Studio .NET 2003 to use the examples. However, by the same token, one would need Windows XP if they wanted to learn about the operating system, or Borland C++ Builder if they were going to learn Builder... If you're new to C# (or Visual Studio .NET, for that matter, and you're willing to learn C#), this book is an excellent reading and practicing material. The writing style is very easy to understand and the examples are easy to follow. The examples also introduce meaningful and useful features of the language, at the same time giving enough beckground to allow one to investigate topics further on their own. The authors clearly state what chapters the reader might find useful and which one can be skipped, depending on the reader's expercience. The chapters are short enough to cover one at a time and to digest without feeling overwhelmed with information. As a C and C++ developer with over five years of experience, I still found this book useful in helping me obtain the initial grasp of C# and get comfortable with the .NET environment to allow me to proceed to more advanced aspects of both the language and the environment. I have no regrets whatsoever about getting this book. In fact, when looking for another book on another subject, I just went with the Step by Step series precicely because of this book.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted May 9, 2005

    If you like to read and not do...

    If you the type of learner that can learn just by reading, well then you may like this book. If you are a type of learner that likes to do hands on excerises, well then look elsewhere. I figured with a book titles Step by Step, they would easily explain and show you how to code in C#. Not in this case. This book is all talk and no play. Well this is a little play on the CD's but half the work is done for you. I would NOT recommend this book. I wish I can return it.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted April 9, 2005

    Pollyanna book.

    If there is one thing I hate it's books that tell me to follow what appears to be a simple set of instructions and when I do, I find that I did NOT get the results the book says I will, and then I have to give up and go on to another subject. I found inconsistancies between the text and the code that were completely irreconsilable. Critical information is omitted, leaving the reader with insufficient info to understand new concepts. The book defers essential info I needed to fill in the answer to the question until I've forgotten the question. Code examples gloss over code replacing important code with '...'. This book is not worthy of sale by Barnes and Noble.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted February 25, 2005

    Woefully incomplete.

    I found this book very incomplete. I would not recommend it for anyone trying to learn C# unless they already know C/C++. The book uses syntax that is never explained assuming the reader will know it. It does not cover such basics as the Accept or Cancel buttons, the status bar, or the toolbar. Having worked through this book, I am now going to buy a more complete one. However, I did find that for a new C# developer with no experience with .NET the 'Step by Step' format was very helpful. No assumptions were made about my experience with .NET (unlike C/C++) and the examples allowed me to try writing the code myself immediately without having to write an entire wrapper myself. In contrast to some other books that do not help the reader navigate the .NET environment or provide examples that the reader could play with, I found this very helpful. Overall, if you already are comfortable with .NET, get a more complete book. If you don't know C/C++, get a book that does a better job teaching the syntax. If you are completly new to .NET and know C/C++ or Java this might be a good starting place, but expect to spend more money later.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted April 15, 2004

    Can't practice the examples...

    To actually learn the examples in this $40-book, you have to have a $1000-software first (Visual Studio .NET Enterprise Developer). Wonderful!!! Should've included some trial version. Returning this book tomorrow, definitely.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted June 3, 2004

    Recomended for New Developers

    I was given this book when I first started using C#. As an experienced programmer I wasn't impressed, but I've found over the last 2 years (I have the original version) that it has been incredibly useful for loaning to aspiring programmers moving from script oriented developent to C#. My version did come with a trial for MS Visual Studio.Net. A trial of Visual Studio is also easy to obtain from Microsoft.

    Was this review helpful? Yes  No   Report this review
Sort by: Showing all of 6 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)