√ C# - 04.常用的数据类型(P29、P53)

  1. C#中所有的数据类型都派生于Object类,根据拷贝策略可分为两类:引用类型(ReferenceType)、值类型(ValueType)。
  2. 引用类型包括(class)、接口(interface)、委托(delegate)。
  3. 值类型包括结构体(struct)、枚举(enum)。
  4. C#预定义了一组简单类型,通过关键字标识。其中,引用类型包括Object类型(object)、字符串类型(string),值类型包括整数类型(sbytebyteshortushortintuintlongulong)、二进制浮点类型(floatdouble)、十进制浮点类型(decimal)、布尔类型(bool)、字符类型(char)。
  5. 变量表示存储位置,指向以其名称所对应的内存地址为起点、以其表示的数据类型所要求的存储空间为长度的一块内存区域。
  6. 变量可分为静态变量实例变量数组元素(params)值参数引用参数(ref)输出参数(out)局部变量
  7. 引用类型变量指向的内存区域中存储着实例地址,值类型变量指向的内存区域中存储着实例本身
  8. 引用类型变量指向的内存区域长度为一个引用的长度,一般等于操作系统的位数,值类型变量指向的内存区域长度为所存储的数据类型的长度。
  9. 引用类型变量指向(Heap)上的内存区域,值类型变量指向(Stack)上的内存区域。
  10. 装箱就是将栈上的值类型转换成堆上的引用类型,拆箱就是将堆上的引用类型转换成栈上的值类型。
  11. 值参数会指向一块新的内存区域,用于存储引用类型变量中的实例地址或值类型变量中的实例本身,而引用参数和输出参数会直接指向原变量所指向的内存区域。
  12. 输出参数与引用参数类似,但传给引用参数的变量需要被明确赋值,而传给输出参数的变量不需要被明确赋值。
  13. 数组参数必须是参数列表中的最后一个参数。
using System;

namespace _04
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("*****测试引用类型*****");
            GetInheritChain(typeof(ClassType));
            GetInheritChain(typeof(InterfaceType));
            GetInheritChain(typeof(DelegateType));
            Console.WriteLine();

            Console.WriteLine("*****测试值类型*****");
            GetInheritChain(typeof(StructType));
            GetInheritChain(typeof(EnumType));
            Console.WriteLine();

            Console.WriteLine("*****测试预定义类型*****");
            GetInheritChain(typeof(object));
            GetInheritChain(typeof(string));
            GetInheritChain(typeof(sbyte));
            GetInheritChain(typeof(byte));
            GetInheritChain(typeof(short));
            GetInheritChain(typeof(ushort));
            GetInheritChain(typeof(int));
            GetInheritChain(typeof(uint));
            GetInheritChain(typeof(long));
            GetInheritChain(typeof(ulong));
            GetInheritChain(typeof(float));
            GetInheritChain(typeof(double));
            GetInheritChain(typeof(decimal));
            GetInheritChain(typeof(bool));
            GetInheritChain(typeof(char));
            Console.WriteLine();
        }

        public static void GetInheritChain(Type type)
        {
            Console.Write(type.FullName);
            type = type.BaseType;
            while (type != null)
            {
                Console.Write($" => {type.FullName}");
                type = type.BaseType;
            }
            Console.WriteLine();
        }
    }

    class ClassType
    {

    }

    interface InterfaceType
    {

    }

    delegate void DelegateType();

    struct StructType
    {

    }

    enum EnumType
    {

    }
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值