由于其保护级别而无法访问该结构

全能的

我在一个类中声明了一个私有结构。

当我尝试使用它时,编译器会引发错误

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; 

我在这里做错了什么?

谢谢。

昂德里·图尼(Ondrej Tucny)

您的编译器很可能会抱怨这一n.wait = 0f;行,因为该结构的字段是私有的。公开它们:

private struct udtThis
{
    public Color col1;
    public Color col2;
    public float wait;
    float fade;
}

然后,您的代码示例就可以正常编译。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

错误:由于其保护级别而无法访问

成员变量由于其保护级别而无法访问

公共类由于其保护级别而无法访问

由于其保护级别而无法访问

“ WebHost”由于其保护级别而无法访问

'ModbusSerialMaster' 由于其保护级别而无法访问

方法由于其保护级别而无法访问

会员由于其保护级别而无法访问

由于保护级别而无法访问

为什么我仍然收到“由于其保护级别而无法访问”错误?

关于局部类(...由于其保护级别而无法访问)

C#AWS SQS客户端由于其保护级别而无法访问

c# 资源中的 SmtpClient 由于其保护级别而无法访问

由于C#中的保护级别而无法访问

由于保护级别c#类而无法访问

由于其保护级别,无法访问方法XXX

由于其保护级别,无法访问Vector.Value

由于其保护级别 C# 无法访问

由于其保护级别,无法访问UserControl元素

由于其保护级别,无法访问“设置”

由于其保护级别,无法访问“ xx”

由于其保护级别,无法访问frmMain

“xxx'由于其保护级别而无法访问”一切都是公开的(我认为)

为什么由于保护级别而无法访问错误“ ObjectPoolingManager.Instance”?

S3和.net Amazon SDK-由于保护级别而无法访问GetObject

尝试在两种形式之间移动文本-“由于保护级别而无法访问”

CS0122 Form1.AvgWaiting由于其保护级别和C#Windows Form中的甘特图而无法访问

CS0122:由于其保护级别,无法访问“ AmazonGlacierClient.ListVaults()”

LINQPad错误:由于其保护级别,无法访问上下文