翻译“新”从 VB.Net 到 C# 的数组
我正在尝试将一些代码从 VB.Net 转换为 C#,但遇到了问题。
我想要翻译的 Vb.Net 代码行是:
client.Applicants = New wcf_Integration.Applicant() {New wcf_Integration.Applicant}
我试图将其翻译为:
Client.Applicants = new wcf_Integration.Applicant[1];
Client.Applicants[0] = new Applicant();
但是,这给了我一个令人讨厌的“对象引用未设置为对象的实例”错误。
对此的任何帮助将非常感激。 :)
I'm trying to translate some code from VB.Net to C#, but I've run into an issue.
The Vb.Net line of code I want to translate is:
client.Applicants = New wcf_Integration.Applicant() {New wcf_Integration.Applicant}
I tried to translate it to:
Client.Applicants = new wcf_Integration.Applicant[1];
Client.Applicants[0] = new Applicant();
However, this is giving me a nasty 'Object reference is not set to an instance of an object' error.
Any help on this would be very much appreciated. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还可以使用数组初始值设定项语法
You can also use the array initializer syntax
可能
Client
为空。因此Client.Applicants
引发异常。与数组无关。May be
Client
is null. SoClient.Applicants
rises an exception. It has nothing to do with the array.试试这个:
try this: