Now that we know that C # is a language, we can learn this language slowly. Many reference books, including the first example of msdn, are "Hello World ", so we should follow international practices.
First, create your first application. C # is a language, not a tool. Therefore, to use C # To develop a program, we must use a development tool that supports C, there are many C # language development tools on the market,
As I said before, I am a loyal user of Microsoft, and C # is developed by Microsoft, So we naturally use Microsoft's visual
Studio. Okay, let's start. Open vs (of course you may not necessarily use vs or sharp
C # development tools such as develop. I will take vs as an example here.) Select "file"> "new" in the upper-left corner. You can select "project" here ", you can also select "website", both
It doesn't matter, because here we only introduce the C # language, not how you develop winform or Asp.net programs. Here we select "project", in the pop-up "new project" dialog box
Select "visual
C # ", then the installed template will be displayed in the right area. vs itself has multiple templates for different program developers to choose from, of course, developers can also create their own project templates.
We may talk about this in the future. Next, we
Select "console application" in the template that has been installed in studio. If you are using vs2008, you will also find a drop-down box in the upper right corner of the template, so that you can choose to create a project. net
Framework version, which includes 2.0, 3.0, and 3.5. You can choose one based on your needs, enter the name of your new project and
The path in the computer, at this time you will see the bottom two is about the solution, by default is to create a new solution for the new project, what is the use of the solution? For example, the current B/S system is divided into three layers,
The three layers of projects can be put under the same solution for ease of management and maintenance. Return to the topic, enter all the information, and click "OK". The first project is created.
Here I create a console program named csharpbasic. After you click "OK" in the dialog box of the new project, Vs will create the following text for you in the path you choose.
File: csharpbasic. sln (if you select "create solution") and a csharpbasic folder, the folder contains the following
Capacity: csharpbasic. csproj, program. CS, Bin folder, OBJ folder, and properties folder. Next we will illustrate this one by one
Something:
1 ,. csproj: it is the abbreviation of the C sharp project, which represents the C # project file. If you create a VB project, it is vbproj. You only need to open it in Notepad mode, it is actually an XML file that records some information about the project, for example:
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <project toolsversion = "3.5" defaulttargets = "build" xmlns = "http://schemas.microsoft.com/developer/msbuild/2003"> <br/> <propertygroup> <br/> <configuration condition = "'$ (configuration) '= ''"> debug </configuration> <br/> <platform condition = "' $ (Platform) '= ''"> anycpu </platform> <br/> <productversion> 9.0.30729 </productversion> <br/> <schemaversion> 2.0 </schemaversion> <br/> <projectguid> {e DFF7D85-4E60-4767-94E0-0262B8EAB0F5} </projectguid> <br/> <outputtype> EXE </outputtype> <br/> <appdesignerfolder> properties </appdesignerfolder> <br/> <rootnamespace> csharpbasic </ rootnamespace> <br/> <assemblyname> csharpbasic </assemblyname> <br/> <targetframeworkversion> v3.5 </targetframeworkversion> <br/> <filealignment> 512 </filealignment> <br /> </propertygroup> <br/> <propertygroup condition = "'$ (Co Nfiguration) | $ (Platform) '= 'debug | anycpu' "> <br/> <debugsymbols> true </debugsymbols> <br/> <debugtype> full </debugtype> <br/> <optimize> false </optimize> <br/> <outputpath> bin/debug/</outputpath> <br/> <defineconstants> debug; trace </defineconstants> <br/> <errorreport> prompt </errorreport> <br/> <WarningLevel> 4 </WarningLevel> <br/> </propertygroup> <br/> <propertygroup condition = "'$ (configuration) | $ (Platform) '= 'release | anycpu' "> <br/> <debugtype> pdbonly </debugtype> <br/> <optimize> true </optimize> <br/> <outputpath> bin/release/</outputpath> <br/> <defineconstants> trace </defineconstants> <br/> <errorreport> prompt </errorreport> <br/> <WarningLevel> 4 </WarningLevel> <br/> </propertygroup> <br/> <itemgroup> <br/> <reference include = "system"/> <br/> <reference include = "system. core "> <br/> <Re Quiredtargetframeworks> 3.5 </requiredtargetframework> <br/> </reference> <br/> <reference include = "system. XML. <br/> <requiredtargetframework> 3.5 </requiredtargetframework> <br/> </reference> <br/> <reference include = "system. data. datasetextension"> <br/> <requiredtargetframework> 3.5 </requiredtargetframework> <br/> </reference> <br/> <reference include = "system. data "/> <br/> <reference include = "System. XML "/> <br/> </itemgroup> <br/> <compile include =" program. CS "/> <br/> <compile include =" properties/assemblyinfo. CS "/> <br/> </itemgroup> <br/> <import project =" $ (msbuildtoolspath)/microsoft.csharp.tar gets "/> <br/> <! -- To modify your build process, add your task inside one of the targets below and uncomment it. <br/> other similar extension points exist, see microsoft.common.tar gets. <br/> <target name = "beforebuild"> <br/> </Target> <br/> <target name = "afterbuild"> <br/> </Target> <br/> --> <br/> </Project>
You do not need to know the meaning of the information here. Because of the configuration information, you can set it through vs. When you open this file with, vs will automatically load the configuration information in this file and load the project
2. program. CS: CS stands for C.
CHARP file (if a VB project is created, module1.vb), the code here is C # code, rather than VB, JavaScript, Java, etc.
Of course, you can write the code. Don't compile it. As for the content in program. CS, we will talk about it later.
3. Bin Folder: only a file named debug can be opened, with A. vshost.exeand A. vshost.exe. manifest file in it.
The name of vshost.exe is the host process and is Visual Studio 2005.
This function improves debugging performance, supports partial trust debugging, and supports expression computing during design. The host process file name contains
Vshost is located in the output folder of the Project. Good debugging friends should be able to understand the power of this thing. We place the mouse over the variable to be debugged during debugging, vs helps us calculate
It is the credit of the host process to calculate this value. However, enabling the host process may
. In these cases, it is necessary to disable the host process to return the correct results. To disable a host process, follow these steps:
Open a project in Visual Studio.
Click properties on the project menu ".
Click the debug tab.
Clear the Enable Visual Studio host process check box.
After the host process is disabled, some debugging functions cannot be used, or the performance may degrade.
Generally, after the host process is disabled, the following situations occur:
It takes more time to start debugging. NET Framework applications.
Expression computing is unavailable during design.
Some trusted debugging is unavailable.
As for that. manifest file, which you can open in notepad, can also be found to be an XML file used to organize and describe isolated applications and parallel components, the <assemblyidentity> element identifies a unique assembly and is used together with other information for binding and activating com classes, interfaces, and libraries, it was previously stored in the registry. In addition, manifests also develops the files and Windows classes that constitute the assembly.
4. OBJ Folder: the folder in the new project should be empty, because you have not run the program, and have not generated any intermediate code or temporary files, so there is nothing here.
5. properties Folder: there is only one file, assemblyinfo. cs. As the name suggests, it is an assembly information file. What is an assembly? Let's talk about it later.
After learning about the files automatically generated by Vs, we will return to vs to see what has changed, you can see that the structure of the project is listed in the tree structure in Solution Explorer. The first is the solution name, And the next level is the project name, the next level is the various folders and files of the project. If the solution name does not appear in your Solution Explorer, set it as follows: "Tools"-> "options"-> click "projects and Solutions"-> check "always show SOLUTION.
Let's talk about this first. Next, let's talk about some other content of this project.