Exception Handling

C supports structured exception handling. As you've experienced, exceptions occur during runtime and are identified by classes, such as the DivideByZeroException class. Most of the basic exception classes can be found in the System namespace some are explicitly listed in the C Language Specification, 16.4. Often the documentation of various classes, methods, and properties indicate exactly what exceptions can be raised. For example, the static Double.Parse method indicates it can raise three...

Text File IO

Certainly one important type of file is the text file, which consists entirely of lines of text separated by end-of-line markers. The System.IO namespace has specific classes to read and write text files. Here's the class hierarchy MarshalByRefObject TextReader (abstract) StreamReader StringReader TextWriter (abstract) StreamWriter StringWriter Although these classes are not descended from Stream, they certainly make use of the Stream class. The two classes I'm going to focus on here are...

First Program cs

FirstProgram.cs (c) 2006 by Charles Petzold Microsoft .NET Framework ) Let's first try to create, compile, and run this program, and then I'll discuss its structure and contents. Although you'll probably eventually use Microsoft Visual Studio to develop .NET programs, that's not your only option. You can actually edit, compile, and run .NET programs from the MS-DOS command line. In many respects, compiling a C program on the command line is quite similar to the way you might have compiled a C...

Decimal Data Type

C also defines a decimal data type that offers about 28 decimal digits of precision. The decimal is useful for storing and calculating numbers with a fixed number of decimal points, such as money and interest rates. In my book Programming in the Key of C , I deliberately covered decimal before floating point. I think it's important for new programmers to use decimal for most applications involving non-integral data types, particularly when the calculations involve money. The C and C++ languages...

Constructors

Consider this expression new Date What this expression actually does depends on whether Date is a structure or a class. If Date is a class, the new operator allocates memory from the heap sufficient to store an object of type Date. This memory must be sufficient for all the instance fields defined in the class. The memory allocation causes these fields to be set to zero, which causes all value-type fields to be set to zero, and all reference-type fields to be set to null. The new operator...