C# 的几种入门方式

目录

C#的第一个程序 Hello World!

手动编译

.Net Core下的HelloWorld

使用Visual Studio 2019

创建项目

Create the application

运行应用程序

关闭应用程序


C#的第一个程序 Hello World!

/*
 * C#的第一个程序 Hello World!
 *
 * HelloWorld.cs
 *
 */

using System;
class HelloWorld{
    public static void Main(){
        Console.WriteLine("Hello World!");
    }
}

手动编译

命令行编译:

csc hello.cs

运行hello.exe:

./hello
Hello, World

.Net Core下的HelloWorld

创建控制台项目

dotnet new console -o hello

创建好后默认就是一个Hello World的控制台程序,进入项目目录直接运行:

cd hello

dotnet run

使用Visual Studio 2019

创建项目

  1. 打开isual Studio 2019.

  2. 在起步窗户中选择 Create a new project.

    'Create a new project' window

  3. 在 Create a new project 窗口的搜索框中输入 console 。接着在语言列表中选择 C#,然后在平台列表中选择Windows 。

    在过滤结果中选择 Console App (.NET Core)模板,点击下一步。

    Choose the C# template for the Console App (.NET Framework)

     

  4. Configure your new project 窗口中,Project name 输入 HelloWorld ,点击 Create.

    in the 'Configure your new project' window, name your project 'HelloWorld'

    Visual Studio 打开一个新的项目

Create the application

Visual Studio 的项目中包含一个默认的Hello World" 代码。

 

View the default Hello World code from the template

按 F5,进入调试模式 。 不过控制台窗口会一闪而过。

添加一些代码:

我们加点代码,让程序在调入回车后再关闭。

  1. 在调用 WriteLine 方法后,立即加入以下代码:

     

    Console.ReadLine();
    
  2. 检验一下你的代码是不是如下:

    Add code to pause the Hello World app

运行应用程序

  1. 点击工具栏上的 HelloWorld 以调试模式运行(或者按 F5)

    Choose the Hello World button to run the app from the toolbar

  2. 在控制台窗口中查看程序。

    Console window showing Hello World!

关闭应用程序

  1. ENTER 关闭黑窗口。

  2. 关闭VS的 Output 面板。

    Close the Output pane in Visual Studio

  3. 关掉 Visual Studio。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值