I have been using basic on an apple machine for about 17 years, and I am still using VB6. However, more and more web development work forces me to enter the C # World. However, the previous VB does not implement the complete object, so I am still weak in the concept of C # objects. To enhance the concept, we must continue to practice. Continuous practice requires a fast programming environment. However, my hardware environment is fixed (the cheapest Chinese notebook I bought three years ago), so I have to find the most efficient way to practice. Fortunately, C # also has command line compilation, so it began to enter the object-oriented world.
Microsoft Visual Studio 8 \ common7 \ toolshas a batch of vsvars32.bats. After running the scripts, you can run csc.exe in any location. I found out later and found that the EXE is located at c: \ winnt \ Microsoft. NET \ framework \ v2.0.50727. In addition, csc.exe is included in all other zookeeper programs. For vsvars32 batch processing, only the CSC path can be temporarily added. In fact, you only need to right-click "my computer" and choose "environment variables" on the "advanced" tab of "properties, add "C: \ winnt \ Microsoft. net \ framework \ v2.0.50727 ", so that CSC can be used directly after each restart.
I set C: \ C # as the working directory. The first input program is still "Hello world". In notepad, enter the following content and save it as hello. CS:
Using system;
Class hello
{
Static void main ()
{
Console. writeline ("Hello, world! ");
}
}
In this way, enter CSC hello. Cs in the working directory. If everything is normal, the following prompt is displayed (complete content ):
Microsoft (r) Visual C #2005 compiler version 8.00.50727.1433
For Microsoft (r) Windows (r) 2005 Framework 2.0.50727
Copyright (c) Microsoft Corporation 2001-2005. All rights reserved.
A hello.exe file is generated under the directory. The running result is "Hello, world!" displayed on the interface! ".
· Note: In command line CSC hello. CS, you cannot drop. cs. Otherwise, the compiler will prompt:
Error cs2001: the source file "hello" is not found"
Fatal error cs2008: unspecified input
The file hello.csdoes not necessarily need this name. You can generate h.exe after executing CSC h.txt, for example, h.txt.
· Extension: A file may not have only one class but multiple classes. The following code is in P. CS:
Using system;
Class M
{
Static void main ()
{
Point P = new point ();
Console. writeline ("x =" + p. x. tostring ());
}
}
Class Point
{
Public Double X = 10;
}
The subsequent code is tested on this basis.
· The disadvantage of manual input is that it is case insensitive. For example, if I start to input main into main and the compilation fails, the following message is displayed:
Error cs5001: The program "C: \ C # \ hello.exe" does not contain the static "Main" method suitable for entry points.