构造函数从 C# 到 Objective-C 的代码
我们必须将 C# 代码转换为 Objective-C 代码,但我很难弄清楚如何创建一个不带参数的构造函数,而另一个则有 2 个参数。 这是我正在尝试转换的 C# 代码:
namespace Account
{
class Program
{
public class Account
{
private double balance;
private int accountNumber;
public Account()
{
balance = 0;
accountNumber = 999;
}
public Account(int accNum, double bal)
{
balance = bal;
accountNumber = accNum;
}
}
}
}
这就是我到目前为止对 Objective C 的了解,不确定它是否正确
@interface classname : Account
{
@private double balance;
@private int accountNumber;
@public Account()
}
接受任何我能得到的帮助,非常感谢,Danny
We have to convert our C# code to Objective-C code and i was having a hard time figuring out how to create one constructor with no arguments while the other with 2 arguments.
This is the C# code that I am trying to convert:
namespace Account
{
class Program
{
public class Account
{
private double balance;
private int accountNumber;
public Account()
{
balance = 0;
accountNumber = 999;
}
public Account(int accNum, double bal)
{
balance = bal;
accountNumber = accNum;
}
}
}
}
And this is what I have so far for the Objective C not sure if it is even correct or not
@interface classname : Account
{
@private double balance;
@private int accountNumber;
@public Account()
}
Open to any help i can get thank you very much, Danny
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需提供两个初始值设定项,其采用一般形式:
you simply provide two initializers, which takes the general form:
Objective C 与其他语言有点不同。与其他语言相比,它的语法更奇怪。但从我所看到的来看,你似乎还没有学到太多关于 Objective-C 的知识。我建议您查看苹果的文档或获取一本书来实际了解 Objective-C 语法的工作原理。学习语法应该不会花太长时间,但您应该这样做。
Objective C is a bit different from other languages. It has a weirder syntax compared to other languages. Though from what I've seen, it appears that you haven't learnt much about objective-c yet. I would recommend you look at apple's documentation or get a book to actually learn about how the objective-c syntax works. It shouldn't take too long to learn the syntax, but here's how you should do it.