簡體   English   中英

錯誤僅在 Unity 內部而不是 Visual Studio,C#

[英]Error Only inside Unity not Visual studio, C#

這行代碼給了我錯誤

錯誤 CS1519:類、結構或接口成員聲明中出現意外符號“=”

public Transform target { get; protected set; } = null;

如果我以錯誤的方式進行 get 和 set,我不明白。 我正在學習教程,我對這個家伙工作得很好。 此外,錯誤僅出現在 Unity 內部。 Visual Studio 不給我任何錯誤消息。

早於 2017 的 Unity 版本不支持 C# 6.0 功能,例如 屬性初始值設定項

使用簡單的后台字段初始化,或升級到支持C# 7.3的最新 Unity (2019)

編輯:

因為對象總是默認為 null

public Transform target { get; protected set; } = null;

public Transform target { get; protected set; }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM