Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

c#输出

作者:__Man︶ㄣ   发布日期:2026-03-19   浏览:74

using System;

class Program
{
    static void Main()
    {
        // 输出简单的文本到控制台
        Console.WriteLine("Hello, World!");

        // 输出变量的值
        int number = 42;
        Console.WriteLine("The number is: " + number);

        // 使用格式化字符串输出
        string name = "Alice";
        int age = 30;
        Console.WriteLine("Name: {0}, Age: {1}", name, age);

        // 使用插值字符串输出 (C# 6.0 及以上版本)
        Console.WriteLine($"Name: {name}, Age: {age}");
    }
}

解释说明:

  1. Console.WriteLine:这是 C# 中最常用的输出函数,用于将文本或变量的值输出到控制台。
  2. 简单文本输出:直接在 Console.WriteLine 中传递字符串即可输出文本。
  3. 输出变量的值:可以使用字符串拼接 (+) 或者格式化字符串来输出变量的值。
  4. 格式化字符串:使用 {0}, {1} 等占位符来指定输出顺序,并通过逗号分隔参数传递给 Console.WriteLine
  5. 插值字符串:在字符串前加上 $ 符号,可以直接在字符串中嵌入变量,语法更简洁。

上一篇:c# 读取配置文件

下一篇:c# 配置文件

大家都在看

c# 二进制

c# 创建目录

c# datatable group by

c# tcp client

c# type.gettype

c# sqlconnection

c# string.format 小数位数

.net和c#

c#获取系统时间

c#游戏开发

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站