15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

68<br />

“Curly Bracket” Languages<br />

Type safe<br />

A second advantage of C# is type-safe language. Basically, if a C# program<br />

stores data, such as a whole number (such as 3 or 49, but not 5.48), the C#<br />

compiler checks to make sure no other part of the program accidentally<br />

changes that whole number into a decimal.<br />

With languages that aren’t type-safe, the compiler lets a program change data<br />

types, such as storing a decimal or negative number where the program<br />

expects a whole number. Obviously, if your program is expecting a whole<br />

number but instead receives a decimal number, the program may get confused<br />

and crash.<br />

.NET compatibility<br />

Because Microsoft invented C#, they also invented a special program — the<br />

.NET framework. The idea behind the .NET framework is that instead of compiling<br />

a C# program into machine language, you compile a C# program into p-<br />

code, which is similar to the bytecode intermediate file <strong>for</strong>mat of Java.<br />

Theoretically, you can run a C# program on any computer that has the .NET<br />

framework on it. Realistically, the only computers that have the .NET framework<br />

are computers running the Windows operating system. So if you write<br />

a C# program, you’re essentially locked into writing programs that run only<br />

under Windows. A band of hardy programmers are trying to rewrite the .NET<br />

framework to run under the Linux operating system, but this doesn’t have<br />

the official blessing of Microsoft, so C# programs are guaranteed to work<br />

only on Windows.<br />

The .NET framework allows you to both<br />

✦ Run C# programs on any computer with the .NET framework.<br />

✦ Write programs in multiple languages that all link together through<br />

the .NET framework, as shown in Figure 3-5.<br />

By letting you write a program with different languages, the .NET framework<br />

lets you use each language’s strengths without being <strong>for</strong>ced to put up with<br />

that language’s weaknesses.<br />

The only <strong>programming</strong> languages you can use with the .NET framework are<br />

languages specifically designed to work with the .NET framework. So if you<br />

want to write a program using a combination of C# and BASIC, you have to<br />

find a BASIC compiler that works with the .NET framework, such as<br />

Microsoft’s own Visual Basic language.<br />

A final advantage of the .NET framework is that it lets you use event-driven<br />

<strong>programming</strong> to create your user interface and then write event handlers in<br />

any .NET language, such as C#.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!