在vs2017中用.net核创建一个c#Hello World的申请

原文

       This topic provides a step-by-step introduction to building, debugging,and publishing a simple.NET Coreconsole application using Visual Studio 2017. Visual Studio 2017 provides a full-featured development environment for building .NET Core applications. As long as theapplication doesn’t have platform-specific dependencies, the application can run on any platform that .NET Coretargets and on any system that has .NET Coreinstalled.
【Prerequisites】
   Visual Studio 2017 with the”.NET Corecross-platform development” workload installed. For more information, see the Prerequisites for .NET Core on Windows topic.
【A simple Hello World application】
   Begin by creating a simple”Hello World” console application.Follow these steps:
(1) Launch Visual Studio 2017.SelectFile > New > Project from the menu bar. In the Add New Project dialog, select the.NET Core node followed by the Console App (.NET Core) project template. In the Name text box, type”HelloWorld”.Select the OK button.
这里写图片描述
(2) Visual Studio loads the development environment.The C# Console Application template for .NET Core automatically defines a class, Program , with a single method, Main , that takes a String array as an argument. Main is the application entry point, the method that’s called automatically by the runtime when it launches theapplication. Any command-linearguments supplied when the application is launched are availablein the args array.
这里写图片描述
The template creates a simple”Hello World”application. It calls the System.Console.WriteLine(String) method to display the literal string “Hello World!” in the console window. By selecting the HelloWorld button with the green arrow on the toolbar,you can run the program in Debug mode. If you do, the console window is visible for only a brief time interval before it closes.This occurs because the Main method terminates and the application ends as soon as the single statement in the Main method executes.
(3)To cause the application to pause before it closes the console window,add the following code immediately after the call to the System.Console.WriteLine(String) method:
这里写图片描述
This code prompts the user to press any key and then pauses the program until a key is pressed.
(4)On the menu bar, select Build > Build Solution.This compiles your program into an intermediate language(IL) that’s converted into binary code by a just-in-time(JIT) compiler.
(5)Run the program by selecting the HelloWorld button with the green arrow on the toolbar.
这里写图片描述
(6) Press any key to closetheconsole window.
【Enhancing the Hello World application】
   Enhance your application to prompt the user for their name and display it along with the date and time.To modify and test the program, do the following:
(1)Enter the following C# code in the code window immediately after the opening bracket that follows the public static void Main(string[] args) line and before the first closing bracket:
这里写图片描述
这里写图片描述
   This code displays “What is your name?” in the console window and waits until the user enters a string followed by the Enter key. It stores this string into a variable named name . It also retrieves the value of the System.DateTime.Now property, which contains the current local time,and assigns it to a variable named date .Finally, it uses a composite format string to display the sevalues in the console window.
(2)Compile the program by choosing Build > Build Solution.
(3)Run the program in Debug modein Visual Studio by selecting the green arrow on the toolbar, pressing F5, or choosing the Debug > Start Debugging menu item. Respond to the prompt by entering a nameand pressing theEnter key.
这里写图片描述
(4)Press any key to closetheconsole window.
You’ve created and run your application.To develop a professional application, take some additional steps to make your application ready for release:
● For information on debugging your application, see Debugging your C# Hello World application with Visual Studio 2017.
● For information on developing and publishing a distributable version of your application, see Publishing your Hello World application with Visual Studio 2017.
【Related topics 】
   Instead of a console application,you can also build a class library with .NET Coreand Visual Studio 2017.For a step-by-step introduction, see Building a class library with C# and .NET Core in Visual Studio 2017.
   You can also develop a .NET Coreconsole app on Mac,Linux,and Windows by using Visual Studio Code,a downloadable code editor.For a step-by-step tutorial, see Getting Started with Visual Studio Code.


译文

       这个主题提供了一个一步步介绍使用vs2017怎样去创建,调试,和发表一个简单的.net 核的申请。Vs2017提供了一个功能齐全的发展的环境对于创建.net核的申请。只要这个申请不受平台的限制,这个平台就可以在由.net核组成的任何的平台上运行安装了。
【前期准备】
   装好有.net 核的可以跨平台的Vs2017,如果想要得到更多的信息,在Windows上看.net核请求社区。
【一个简单的Hello World申请】
(1)开始创建一个简单的“Hello World”输出申请,跟着下面的步骤走
   打开vs2017,从工具栏中选择文件>新建>项目。在添加新的项目目录中,选择.net 核,再选择生成APP项目材料。在名字的输入框中打上“He’llWorld”,选择OK按钮。
这里写图片描述
(2)vs开发环境界面就出来了。面向c#程序材料用.net核自然而然生成一个类Program,有一个简单的方法Main,把string当做指定值,Main是一个进或出的口的点,当申请自动创建的时候自动生成的方法。任何命令行参数提供数组当创建可用申请时。
这里写图片描述
这个模板创建一个简单的“Hello World”申请。它叫做System.Console.WriteLine(String)方法去放置这个字符串“Hello World”在输出框。通过在工具栏选择绿色按钮运行HelloWorld,你可以运行这个程序在调试模式下。如果你这样做了,这个输出窗口在它关闭之前在一个简短的时间间隔内是可见的。这个情况发生的原因是因为当简单的声明在Main方法中执行时Main方法结束并且申请结束。
(3)让这个申请在它关闭输出窗口之前停止,立即在System.Console.WriteLine(String)方法之后加上下面的代码:
这里写图片描述
这些代码让使用者按下任意键然后在一个键按下的时候程序停止
(4)在菜单栏中,选择新建>生成解决方案。这将您的进程转换成中间语言,及时转换成二进制的代码。
(5)在工具栏中按下绿色的键使这个Hello World程序运行
这里写图片描述
(6)按下任意键关闭窗口
【增强 这个Hello World应用】
   增强你的应用让用户输入他们的姓名和显示他的时间。去修改和测试这个程序,跟着下面做:
1.在打开窗体的时候立马在开括号后面写下面的代码,
public static void Main(string[] args)
在遇到第一个闭括号之前跟着它的线写:
这里写图片描述
这里写图片描述
   这些代码显示的是“你的名字是什么?”在控制窗口然后等待用户按下任意键。然后把它存放在一个可变的名字中。它检索System.dateTime.Now 的属性值,包含当时的时间,并且把它赋值给可变的字符串。最后,使用一个复合的字符串去显示它的属性值在控制台窗口
(2)通过选择创建–创建解决方案来编译项目
(3)通过选择工具栏上绿色的按钮来运行这个程序,或者按下F5,或者选择菜单栏中的调试–开始调试这个项目。回应提示,按下你的名字或者enter键即可。
这里写图片描述
(4)按下任意键去关闭控制台窗口
你已经创建和运行你的应用程序。做一些额外的步骤使你的应用程序更加专业,然后准备好发布
●在应用程序的调试信息,看你c# Hello World应用程序的调试信息
●在发展和发布一个可分配的应用程序时,看用vs2017发布你的Hello World应用程序
【有关主题】
   除了创建一个控制台应用程序,你可以用vs2017使用.net核创建一个类库。每一步的讲解介绍,看在vs2017中用C#和.net 核创建一个类库。
   你同样可以使用vs代码(一个可以下载的代码编辑库)在mac,Linux和Windows上创建一个.net控制台APP,一个详细的介绍,看用vs代码开始。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 23
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 23
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值