我在一个类中声明了一个私有结构。
当我尝试使用它时,编译器会引发错误
struct inaccessible due to its protection level
这是C#代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class HUDanimator : MonoBehaviour
{
private struct udtThis
{
Color col1;
Color col2;
float wait;
float fade;
}
private udtThis[] m = new udtThis[2];
void Start()
{
udtThis n; //raises the compiler error
n.wait = 0f;
我在这里做错了什么?
谢谢。
您的编译器很可能会抱怨这一n.wait = 0f;
行,因为该结构的字段是私有的。公开它们:
private struct udtThis
{
public Color col1;
public Color col2;
public float wait;
float fade;
}
然后,您的代码示例就可以正常编译。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句