Skip to content

this 在Struct 中是可读可写

this 在Class中是只读

例子如下:

C#
//Class
public class A
{
   public A(string json)
   {
        this = JsonSerializor.DeSerialize<T>(json) ; // 编译错误
   }
   public string Name{get;set;}
}
//Struct
public struct B
{
   public B(string json)
   {
        this = JsonSerializor.DeSerialize<T>(json) ; // OK,没有问题
   }
   public string Name{get;set;}
}

转换自: https://www.cnblogs.com/atwind/archive/2013/02/23/2923267.html