C# Struct 和class的区别

1.struct是值类型,class是引用类型

2. 结构不能声明默认的构造函数

3.结构体不支持继承

  static void Main(string[] args)
        {
            Book book1;
            book1.title = "Gone with the wind";
            book1.author = "Tom";
            Book book2 = new Book();
            book2.title = "west tour";
            book2.author = "ShiNaiAn";
        }

        struct Book {
            public string title;
            public string author;
        }

 什么时候使用struct

考虑使用:如果类型的实例很小而且通常存活期都很短或者一般都嵌入到其它对象中使用

原文地址:https://www.cnblogs.com/kingsmart/p/15620964.html