Summary

   


This chapter presented you with another C# source code example with the ability to perform simple calculations. Many essential constructs and concepts were extracted from this program to extend the knowledge you gained from the previous chapter.

The following are the important elements covered in this chapter:

A variable of type int can be used to store whole numbers and can take part in standard arithmetic calculations.

Namespaces help programmers keep their classes organized and accessible to other programmers for reuse purposes.

The System namespace in the .NET Framework class library contains many fundamental classes.

Use comments to describe the overall intent of the source code instead of merely restating what the code does.

A string value consisting of digits that form a whole number can be converted to a value of type int. Conversely, a value of type int can also be converted to a value of type string.

A method is defined by writing its method header (which includes access modifier, return type, name and formal parameters), by indicating its method body with {} and by writing the statements of the method inside the method body.

A method call must include the name of the called method and an argument list that matches the formal parameter list of the called method. When a method is called, the values held by the arguments are assigned to the formal parameters of the called method. A method can return a value, in which case, the method call can be regarded as holding this value just after the method called returns.

When positioned between two numeric values, the + operator will perform a standard arithmetic addition but, if positioned between two strings, will perform a string concatenation.

The Math class found in the System namespace of the .NET Framework class library contains many helpful methods to perform various mathematical calculations.

Instead of using just one method to solve a complex computational problem, break the problem into several simpler methods. Every method should accomplish just one clear task. Such a method is described as being cohesive.


   


C# Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 286
Authors: Stephen Prata

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