【发布时间】:2019-02-10 20:49:51
【问题描述】:
这是 Unity 5.5.0 上的结构 我对 c# 很陌生,不太了解属性和结构。
这会在this.X 期间分配错误。
我假设您不能更改结构上的值,而关键字 this 指的是结构的属性
在将控制权返回给调用者之前,必须完全分配自动实现的属性“Point.X”的支持字段。考虑从构造函数初始化器调用默认构造函数。 (CS0843) (汇编-CSharp) [LN 15]
“this”对象在其所有字段都分配给 (CS0188) (Assembly-CSharp) [LN 16] 之前不能使用。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public struct Point
{
// Don't undertstand why "public int X, Y" works fine but not this
public int X { get; set; }
public int Y { get; set; }
//public int X,Y;
public Point(int x, int y)
{
// LN 15
this.X=x;
this.Y=y;
}
}
【问题讨论】:
-
尝试将
public Point(int x, int y)更改为public Point(int x, int y) : this() -
欢迎来到 Stack Overflow。希望上面的链接将有助于回答您的问题并为您提供解决问题所需的想法。请注意,我通过将错误消息复制到谷歌搜索中找到了此链接。这通常是解决此类问题的一种非常快速的方法。
标签: c#