Although the Visual Studio IDE is what you will probably be using for your commercial projects, the C# command-line compiler is the easiest way to compile and run most of the sample programs shown in this book. To create and run programs using the C# commandline compiler, you will follow these three steps:
Enter the program using a text editor.
Compile the program.
Run the program.
Entering the Program
The programs shown in this book are available from Osborne’s web site: www.osborne.com. However, if you want to enter the programs by hand, you are free to do so. In this case, you must enter the program into your computer using a text editor, such as Notepad. Remember, you must create text-only files, not formatted word-processing files, because the format information in a word processor file will confuse the C# compiler. When entering the program, call the file Example.cs.
Compiling the Program
To compile the program, execute the C# compiler, csc.exe, specifying the name of the source file on the command line, as shown here:
C:\>csc Example.cs
The csc compiler creates a file called Example.exe that contains the MSIL version of the program. Although MSIL is not executable code, it is still contained in an exe file. The Common Language Runtime automatically invokes the JIT compiler when you attempt to execute Example.exe. Be aware, however, that if you try to execute Example.exe (or any other exe file that contains MSIL) on a computer for which the .NET Framework is not installed, the program will not execute because the CLR will be missing.
Note Prior to running csc.exe, you may need to run the batch file vcvars32.bat, which is typically found in the \Program Files\Microsoft Visual Studio 8\VC\Bin directory. Alternatively, you can activate a command-prompt session that is already initialized for C# by selecting a Visual Studio 2005 Command Prompt from the list of tools shown under the Microsoft Visual Studio 2005 entry in the Start
Programs menu of the task bar. Alternatively, you can select SDK Command Prompt shown under the Microsoft .NET Framework SDK 2.0 entry in the Start
Programs menu of the task bar.
Running the Program
To actually run the program, just type its name on the command line, as shown here:
C:\>Example
When the program is run, the following output is displayed:
A simple C# program.
Subscribe to:
Post Comments (Atom)
Archives
-
▼
2008
(167)
-
▼
August
(36)
- Delay Sign an Assembly in C#
- Verify That a Strong-Named Assembly Has Not Been M...
- Give an Assembly a Strong Name in C#
- Create and Manage Strong-Named Key Pairs in C#
- Access a Program Element That Has the Same Name as...
- Selectively Include Code at Build Time in C#
- Access Command-Line Arguments in C#
- Create and Use a Code Library in C#
- Create and Use a Code Module in C#
- Short-Circuit Logical Operators in C#
- Relational and Logical Operators in C#
- Arithmetic Operators in C#
- Type Conversion of Expressions in C#
- C# Type Conversion and Casting
- The Scope and Lifetime of Variables in C sharp
- A Closer Look at Variables in C#
- C# Literals
- C# Some Output Options
- C# The bool Type
- C# Characters
- C# The Decimal Type
- C# Floating-Point Types
- C# Integers
- C# Value Types
- The C# Class Library
- C# Identifiers
- The C# Keywords
- Semicolons, Positioning, and Indentation in C#
- Handling Syntax Errors in C#
- Using the Visual Studio IDE
- Using csc.exe, the C# Command-Line Compiler
- A First Simple Program
- Inheritance
- Polymorphism
- Encapsulation
- C# Object-Oriented Programming
-
▼
August
(36)
Wondering where to go in 2021? Things to do has ranked as the best include a remote, idyllic island, the design capital .
ReplyDelete