c#

C#中HelloWorld程序的多种变体

小樊
83
2024-07-04 15:40:22
栏目: 编程语言

  1. 最基本的HelloWorld程序:
using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Hello, World!");
    }
}
  1. 使用字符串变量存储HelloWorld字符串:
using System;

class Program
{
    static void Main()
    {
        string message = "Hello, World!";
        Console.WriteLine(message);
    }
}
  1. 使用字符串插值输出HelloWorld:
using System;

class Program
{
    static void Main()
    {
        string name = "World";
        Console.WriteLine($"Hello, {name}!");
    }
}
  1. 使用静态方法输出HelloWorld:
using System;

class Program
{
    static void Main()
    {
        PrintHelloWorld();
    }

    static void PrintHelloWorld()
    {
        Console.WriteLine("Hello, World!");
    }
}
  1. 使用命令行参数输出HelloWorld:
using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello, " + args[0] + "!");
    }
}

这些是C#中HelloWorld程序的一些变体,可以根据需要选择适合自己的方式来输出HelloWorld字符串。

0
看了该问题的人还看了