111,130
社区成员
发帖
与我相关
我的任务
分享
public struct STATS_CONST
{
int i1;
int i2;
int i3;
string s1;
string s2;
public STATS_CONST( int ii1, int ii2, int ii3, string ss1, string ss2 )
{
i1 = ii1;
i2 = ii2;
i3 = ii3;
s1 = ss1;
s2 = ss2;
}
}
public readonly STATS_CONST[] astStatsConst =
{
new STATS_CONST( 0, 0, 0, "Pot", "counts" ),
new STATS_CONST( 0, 0, 0, "Position", "" ),
new STATS_CONST( 0, 0, 0, "Battery Capacity", "mAh" ),
new STATS_CONST( 0, 0, 0, "Battery Voltage", "V" ),
new STATS_CONST( 0, 0, 0, "Battery Current", "mA" ),
new STATS_CONST( 0, 0, 0, "Battery Temperature","K" ),
new STATS_CONST( 0, 0, 0, "Battery Charge Current","mA" ),
new STATS_CONST( 0, 0, 0, "Pot Error", "" ),
new STATS_CONST( 0, 0, 0, "Movement Error", "" )
};
错误 1 “CATesting.Program.astStatsConst”的类型为“CATesting.Program.STATS_CONST[]”。只能用 null 对引用类型(字符串除外)的常量进行初始化 E:\Projects\Study\CATesting\Program.cs 31 52 CATesting
public struct STATS_CONST
{
public int x;
public int y;
public int z;
public string str1;
public string str2;
public STATS_CONST(int x, int y, int z, string a, string b)
{
this.x = x;
this.y = y;
this.z = z;
this.str1 = a;
this.str2 = b;
}
}
public STATS_CONST[] astStatsConst = {
new STATS_CONST(0,0,0,"Pot","counts"),
new STATS_CONST(0,0,0,"Position","")
};
public const STATS_CONST[] astStatsConst =
{
{ 0, 0, 0, "Pot", "counts" },
{ 0, 0, 0, "Position", "" },
{ 0, 0, 0, "Battery Capacity", "mAh" },
{ 0, 0, 0, "Battery Voltage", "V" },
{ 0, 0, 0, "Battery Current", "mA" },
{ 0, 0, 0, "Battery Temperature","K" },
{ 0, 0, 0, "Battery Charge Current","mA" },
{ 0, 0, 0, "Pot Error", "" },
{ 0, 0, 0, "Movement Error", "" }
};