Author: Rod Stephens
Pub Date: 2014
Size: 15 Mb
Well-known C# expert Rod Stephens gives novice and experienced developers a comprehensive tutorial and reference to standard C#. This new title fully covers the latest C# language standard, C# 5.0, as well as its implementation in the 2013 release of Visual Studio. The author provides exercises and solutions; and his C# Helper website will provide readers and students with ongoing support. This resource is packed with tips, tricks, tutorials, examples, and exercises and is the perfect professional companion for programmers who want to stay ahead of the game.
Author Rod Stephens is a well-known programming authority and has written more than 25 programming books covering C#, Java, VB, and other languages. His books have sold more than 60,000 copies in multiple editions. This book’s useful exercises and solutions are designed to support training and higher education adoptions.
•Learn the full range of C# programming language features
•Quickly locate information for specific language features in the reference section
•Familiarize yourself with handling data types, variables, constants, and much more
•Experiment with editing and debugging code and using LINQ
The IL code is fairly cryptic; although, if you look closely you can see the method’s declaration and calls to Console.WriteLineand Console.ReadLine.
IL code looks a lot like assembly language but it’s not. Assembly language is a (barely) human-readable version of machine code that can run on a specific kind of computer. If the program were translated into assembly or machine code, it could run only on one kind of computer. That would make sharing the program on different computers difficult.
To make sharing programs on multiple computers easier, IL provides another layer between C# code and machine code. It’s like a virtual assembly language that still needs to be compiled into executable machine code. You can copy the IL code onto different computers and then use another compiler to convert it into machine code at run time. In .NET, the Common Language Runtime(CLR) performs that compilation.
CLR is a virtual machine component of the .NET Framework that translates IL into native machine code when you run a C# program. When you double-click a C# program’s compiled executable program, the CLR translates the IL code into machine code that can be executed on the computer.
The CLR uses a just-in-time compiler(JIT compiler) to compile pieces of the IL code only when they are needed. When the program is loaded, the loader creates a stub for each method. Initially, that stub points to the method’s IL code.
When the program invokes the method, the JIT compiler translates its IL code into machine code, makes the stub point to it, and then runs the machine code. If the program calls the method again later, its stub already points to the machine code, so the method doesn’t need to be compiled again. Figure 1-1 shows the process graphically.
Usually, the time needed to compile a method is small, so you don’t notice the tiny bits of extra time used as each method is called for the first time. After a method is compiled, it runs a tiny bit faster when it is called later.
If a method is never called by the program, it is never compiled by the JIT compiler, so the compiler saves some time.
By using all of these tools, you can build standalone programs to run on desktop systems, phone or tablet applications, websites, networked applications, and all sorts of other programs.
A compiled C# program needs the CLR to execute, and most programs also need the .NET Framework. That means to run a program, a computer must have the .NET Framework installed.
If Visual Studio is installed on the computer, the .NET Framework is also installed. That means you can usually copy a compiled C# application onto the computer and it will run. (Of course, you should never copy a compiled program from a source you don’t trust! This method works if you want to share a program with your friends, but don’t just grab any old compiled C# program off the Internet.)
Most installers also install the .NET Framework if needed, so if you use an installer, the .NET Framework will be installed if it’s not already on the machine. For example, ClickOnce deployment installs the .NET Framework if necessary.
You can also install the .NET Framework manually by downloading an installer or by using a web installer. To find the latest installers, go to Microsoft’s Download Center at www.microsoft.com/download/default.aspxand search for .NET Framework.
Most of the .NET Framework features are backward compatible, so usually you can install the most recent version, and programs built with older versions will still run. If you do need a particular version of the .NET Framework, search the Download Center for the version you need.
A C# program cannot stand completely alone. To create, compile, and run a C# program, you need several tools. You can create a C# program in a text editor, but it’s much easier to use Visual Studio to write and debug programs. After you write a program, the C# compiler translates the C# code into IL code. At run time, the CLR (which is part of the .NET Framework) uses JIT compilation to translate the IL code into native machine code for execution.
You can use NGen to precompile assemblies and install them in the GAC, so they don’t need to be compiled at run time by the JIT compiler. In many cases, however, that won’t save much time. If the