C# 在课堂上达到课堂功能? 我把代码从C++翻译成C,现在我遇到了这个问题,所以我不能达到我必须达到的功能。 public struct TargetList_t { public float Distance; public float[] AimbotAngle = new float[3]; public float[] aimbotAngle = new float[3]; public float[] myCoords = new float[3]; public float[] enemyCoords = new float[3]; public TargetList_t(float[] aimbotAngle, float[] myCoords, float[] enemyCoords) { Distance = Get3dDistance(myCoords[0], myCoords[1], myCoords[3], enemyCoords[0], enemyCoords[1], enemyCoords[2]); AimbotAngle[0] = aimbotAngle[0]; AimbotAngle[1] = aimbotAngle[1]; AimbotAngle[2] = aimbotAngle[2]; } };
这是我的课C# 在课堂上达到课堂功能? 我把代码从C++翻译成C,现在我遇到了这个问题,所以我不能达到我必须达到的功能。 public struct TargetList_t { public float Distance; public float[] AimbotAngle = new float[3]; public float[] aimbotAngle = new float[3]; public float[] myCoords = new float[3]; public float[] enemyCoords = new float[3]; public TargetList_t(float[] aimbotAngle, float[] myCoords, float[] enemyCoords) { Distance = Get3dDistance(myCoords[0], myCoords[1], myCoords[3], enemyCoords[0], enemyCoords[1], enemyCoords[2]); AimbotAngle[0] = aimbotAngle[0]; AimbotAngle[1] = aimbotAngle[1]; AimbotAngle[2] = aimbotAngle[2]; } };,c#,c++,class,C#,C++,Class,这是我的课 TargetList_t TargList; 这就是我试图达到它的目的。 在C++中,可以通过< /p>调用默认构造函数。 TargetList_t TargList; 在C#中,您总是希望使用new关键字: // init your constructor parameters float[] aimbotAngle = new float[1]; float[] myCoords = new float[1]; float[] enemyCoords = new floa
TargetList_t TargList;
这就是我试图达到它的目的。 在C++中,可以通过< /p>调用默认构造函数。
TargetList_t TargList;
在C#中,您总是希望使用new
关键字:
// init your constructor parameters
float[] aimbotAngle = new float[1];
float[] myCoords = new float[1];
float[] enemyCoords = new float[1];
// call constructor
var targList = new TargetList_t(aimbotAngle , myCoords , enemyCoords);
注:
- 您可能希望将
更改为struct
,因为这是(有争议的)它的外观class
<> L> >P>在C++中,你可以添加后缀或前缀,以表示它是<代码>类型,<代码> int >代码>或其他什么,在C语言中,你一般不这样做,所以你的类名应该是<代码> TalkList。此外,
List
在.Net framework中是一个众所周知的类,因此我希望该类要么从中派生,要么从名称中删除List单词,如TargetList\t
=>Targets
公共浮动距离代码>=>公共浮动距离{get;set;}
您需要调用构造函数吗?类似于
TargetList\u t TargetList=newtargetlist\u t(aimbotAngle、mycors等其他参数)代码>旁注:您很可能想要的是类,而不是结构。C++的结构与C#的不同,在这种情况下,C#的结构不起作用。此类没有defaut构造函数