我在一个类中声明了一个私有(private)结构。
当我尝试使用它时,编译器抛出错误
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)的。公开它们:
private struct udtThis
{
public Color col1;
public Color col2;
public float wait;
float fade;
}
然后您的代码示例就可以正常编译了。
关于c# - 由于其保护级别而无法访问结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53362921/