溫馨提示×

C#中HelloWorld程序的多種變體

c#
小樊
90
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
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女