C#的数据结构

变量类型

  1. 值类型

    1. bool   布尔型
    2. btye    8位无符号整数 0x00~0xff
    3. char    16位无符号整数
    4. decimal 128位精确的10进制值
    5. double    64位
    6. float       32 位
    7. int           32位
    8. long        64位
    9. sbyte     8位有符号
    10. short      16位
    11. uint       32位无符号
    12. ulong    64位无符号
    13. ushort   16位无符号 

           sizeof 可以获取变量的位数

  1. 引用类型
    1. 引用类型不包含存储在变量中的值,引用类型指向内存位置
    2. 内置的引用类型有 object dynamic string
    3. 对象类型
    4. 动态类型
      1. 可以存储任何类型的值到变量中,在运行时生效
    5. 字符串类型
      1. String str= “Helloworld“;
      2. 加引导字符@ ,可以把字符串中的 ‘\'字符看待  @"\\HelloWorld"  == “\HelloWorld”
      3. 字符串可以任意换行,空格键和换行符都算在字符串长度之内
        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        
        namespace StudentCShrap
        {
            class MainClassTest
            {
                static void Main(string[] args)
                {
                    String str = "Helloworld\n\n\n";
                    Console.WriteLine(str.Length);//13 length
                    str = @"12345897522
                            4152454
                                524154";
                    Console.WriteLine(str.Length);//72 length
                    
        
        
                    Console.ReadKey();
                    
                }
            }
        }
        
  2. 指针类型
    1. 存储另一种类型的内存地址 跟C和C++的指针有相同的作用
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      
      namespace StudentCShrap
      {
          class MainClassTest
          {
              static void Main(string[] args)
              {
                  int* Leng; //错误 CS0214: 指针和固定大小缓冲区只能在不安全的上下文中使用
                  Console.ReadKey();
                  
              }
          }
      }
      
发布了24 篇原创文章 · 获赞 5 · 访问量 3211

猜你喜欢

转载自blog.csdn.net/Ellis1993/article/details/105261289