c # special treatment - the use of visual studio to write the first program

Although the program has written a text editor and compiler is sufficient, but we still have to in order to increase the efficiency of the use of IDE.

All of our next tutorials will be achieved in the visual studio, visual studio short vs, IDE is a Microsoft-developed software, use the software that enables developers to do more with less efficiency.

Software where to download it? First recommendation official website: https: //visualstudio.microsoft.com/zh-hans/vs/ here to download the latest version of vs, to note that, vs there are three versions, namely Community Edition, Professional Edition, and Enterprise Edition, recommended download community Edition, because the community version is free. Three versions of the function is not very different, for starters, but no need to download a professional version and then try to crack, of course, if you want to spend money on it when I did. Download button as shown:

If you do not want to own the latest version can be found online, many sites are available for download. Although in 2019, but I was here with the 2015 version, too lazy to upgrade a laptop or home version 2013, using them is not very different.

Download and install a process may be slow, after all, it is a huge software, open the software after installation, create a new project, the following two methods can create.

After opening the new window will look like, select the visual C # program, and then select a console application, the console application is that the black box box program, the future will see every day. Then the name, just change your own is like one you like, I've changed a hello, you can also set up their own position. Set up click OK.

After the new good, the general layout is as follows:

You can see, vs automatically generate the code for our most basic, it is still very easy to use.

Look far right, there is a "Solution Explorer" small window, this window we just have to build the project, the project is stored in the project we have just built a set position among the hard disk can be found. We can also see a project called .cs file extension, this is our built vs source files, code written here. If you accidentally closed window solution can not be found, you can view - open the Solution Explorer.

Now we know vs, began to write the first program, let us know the code.

首先,看第九行,class的意思是类,类是程序最基本的单位,将来写程序会有很多个类,这里只有一个,后面的Program是类的名字,可以自己取的。

再看第七行namespace的意思是命名空间,因为会有很多类,所以需要一个命名空间来管理,后面的hello是自己取的命名空间的名字。

c#作为一个高级语言,最基本的功能都是现成的,这些都存在一个命名空间里,我们要调用这些命名空间里的功能,就是第一行到第六行的内容了,using的意思是引用命名空间,using后面都是被引用的命名空间的名字。

第十一行,static void Main(string[] args),这个是Main函数,也叫Main方法,写死的,这里是程序的入口,不管多复杂的程序,都要从Main方法开始执行。这一行除了Main之外的其他单词的意思以后会慢慢熟悉。

大括号,我们在代码中可以看到,程序是一层套着一层的,命名空间后面有大括号,里面包括类,类后面有大括号,后面包括方法,方法后面包括大括号,用来写内容,将来还要学到一些带大括号的语句,切记,大括号都是成对出现的。

分号,我们可以从代码中看到,每一条语句都是以分号结束的。

符号问题:使用英文符号,否则会报错。谁让这是人家歪果仁发明的呢?

 认识完这些基本的代码,我们该写点自己的东西了

我在Main方法里写一个语句 Console.WriteLine("HelloWorld"); 

这个语句的意思是,在控制台输出引号内的内容,即HelloWorld,务必记得写引号,结尾别忘了分号……我们的第一个程序到这里就写完了。我们点击运行,看一下效果

什么?没看清?当然了,因为已经输出完了嘛……那有没有办法让他停住呢?我们这里加一行代码 Console.ReadKey(); 意思是等待按键并读取,也就是需要我们输入一个东西,我们什么都不按它就一直等着我们了,达到了让他停住的效果,我们看清了之后随便按一个键,就可以把它关闭了。我们看下效果

现在效果好多了吧。现在我们已经学会了使用vs写程序了。

Guess you like

Origin www.cnblogs.com/hmswt/p/11295507.html