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

c# 数据类型

作者:翻成云恨雨愁   发布日期:2026-01-29   浏览:27

// C# 数据类型示例

using System;

class Program
{
    static void Main()
    {
        // 值类型 (Value Types)
        int integer = 10; // 整数类型
        float floatingPoint = 3.14f; // 单精度浮点数
        double doublePrecision = 3.141592653589793; // 双精度浮点数
        decimal highPrecision = 123.456789m; // 高精度小数,常用于金融计算
        char character = 'A'; // 字符类型
        bool boolean = true; // 布尔类型

        // 引用类型 (Reference Types)
        string text = "Hello, World!"; // 字符串类型
        object obj = new object(); // 对象类型
        DateTime date = DateTime.Now; // 日期时间类型

        // 输出各种数据类型的值
        Console.WriteLine($"Integer: {integer}");
        Console.WriteLine($"Floating Point: {floatingPoint}");
        Console.WriteLine($"Double Precision: {doublePrecision}");
        Console.WriteLine($"High Precision: {highPrecision}");
        Console.WriteLine($"Character: {character}");
        Console.WriteLine($"Boolean: {boolean}");
        Console.WriteLine($"String: {text}");
        Console.WriteLine($"Object: {obj}");
        Console.WriteLine($"Date and Time: {date}");
    }
}

解释说明:

  • 值类型 (Value Types):包括 int, float, double, decimal, char, 和 bool。这些类型的变量直接存储数据值。
  • 引用类型 (Reference Types):包括 string, object, 和 DateTime。这些类型的变量存储的是对对象的引用(即内存地址),而不是实际的数据值。
  • 输出:通过 Console.WriteLine 方法将不同数据类型的值输出到控制台,以便查看和验证。

这个示例展示了如何在 C# 中声明和使用常见的数据类型,并通过控制台输出它们的值。

上一篇:c#队列

下一篇:c# rabbitmq

大家都在看

c# 二进制

c# datatable group by

c# tcp client

c# type.gettype

c# sqlconnection

c# string.format 小数位数

.net和c#

c#获取系统时间

c#游戏开发

c#网络编程

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

Laravel 中文站