gpt4 book ai didi

C# const 结构列表

转载 作者:太空狗 更新时间:2023-10-30 00:41:53 24 4
gpt4 key购买 nike

我想创建一个可以从其他类引用的查找表,所以我尝试创建一个 const 结构列表,如下所示:

    public struct DataRouting1
{
public struct tParameters
{
private readonly bool prvFieldbus;
private readonly int prvAddressMax;
private readonly string prvTypeLabel;
private readonly byte prvXTPtype;
private readonly string prvPointLabel;
private readonly int prvPointMin;
private readonly int prvPointMax;
private readonly int prvPointValue;
private readonly int prvQuantityMax;

public tParameters(bool Fieldbus, int AddressMax, string TypeLabel, byte XTPtype, string PointLabel, int PointMin, int PointMax, int PointValue, int QuantityMax)
{
this.prvFieldbus = Fieldbus;
this.prvAddressMax = AddressMax;
this.prvTypeLabel = TypeLabel;
this.prvXTPtype = XTPtype;
this.prvPointLabel = PointLabel;
this.prvPointMin = PointMin;
this.prvPointMax = PointMax;
this.prvPointValue = PointValue;
this.prvQuantityMax = QuantityMax;
}
public bool Fieldbus { get { return Fieldbus; } }
public int AddressMax { get { return AddressMax; } }
public string TypeLabel { get { return TypeLabel; } }
public byte XTPtype { get { return XTPtype; } }
public string PointLabel { get { return PointLabel; } }
public int PointMin { get { return PointMin; } }
public int PointMax { get { return PointMax; } }
public int PointValue { get { return PointValue; } }
public int QuantityMax { get { return QuantityMax; } }
}
public static readonly List<tParameters> Parameter = new List<tParameters>
{

new tParameters (true, 250, "Fieldbus Digital Input", 0x80, "Number", 1, 65535, 0, 255),
new tParameters (true, 250, "Fieldbus Digital Output", 0x81, "Number", 1, 65535, 0, 255),
new tParameters (true, 250, "Fieldbus Input Register", 0x82, "Number", 1, 65535, 0, 255),
.
.
.
};
}

我是这样使用的:

    if (DataRouting1.Parameter[Index].Fieldbus == false)
.
.

这可以正确编译,但是当我运行它时程序崩溃了,说它有内存溢出。我单步执行程序,发现当我进入上面一行时,应用程序调用了该行

                public bool Fieldbus { get { return Fieldbus; } }

并无限期地留在那里。步进在“get”和“return Fieldbus”之后突出显示“{”之间切换,因此它显然进入了无限循环。

知道我做错了什么吗?

最佳答案

您需要返回您的私有(private)备份变量this.prvFieldbus。您的其他属性也是如此。

关于C# const 结构列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18205549/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com