帮助与理解C#代码移植到Objective-C [英] Help with understanding C# code and porting to Objective-C

查看:123
本文介绍了帮助与理解C#代码移植到Objective-C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我有这个原型,被写了有人在C#else和我试图把它变成的Objective-C。现在,我还没有与C#任何正式的经验,所以我不知道这一切呢。我明白的前三个变量,但我跑成什么了第四和第五行(C_DATA)正在做的问题。是第四个宣布方法,然后第五定义它还是发生了什么? !感谢您的帮助。



 公共类C_DATA {
公共双重价值;
公众诠释标签;
公众诠释身份证;
公共C_DATA(){}
公共C_DATA(双VAL){
值= VAL;
}
}


解决方案

的第四和第五行是在C#构造函数。他们是等价于[[C_DATA的alloc]初始化]在Objective-C链。 C#允许你超载基础上,他们采取的参数的构造函数。这相当于具有Objective-C的两种不同的初始化方法:

  @interface CDATA出现:NSObject的
{
双重价值;
INT标签;
INT ID;
}

@财产双重价值;
@property INT标签;
@property INT ID;

- (id)的初始化;
- (ID)initWithValue:(双)值;

@end


Ok, I have this prototype that was written by someone else in C# and I'm trying to put it into Objective-C. Now, I haven't had any formal experience with C# yet, so I don't know everything about it yet. I understand what the first three variables are, but I'm running into problems with what the fourth and fifth lines (c_data) are doing. Is the fourth declaring a method and then the fifth defining it or what's happening? Thanks for your help!

public class c_data {
    public double value;
    public int label;
    public int ID;
    public c_data() { }
    public c_data(double val) {
        value = val;
    }
}

解决方案

The fourth and fifth lines are constructors in C#. They are the equivalent to [[c_data alloc] init] chains in objective-c. C# allows you to overload constructors based on the parameters they take. This is equivalent to having two different initialization methods in Objective-C:

@interface CData : NSObject
{
   double value;
   int label;
   int ID;
}

@property double value;
@property int label;
@property int ID;

-(id) init;
-(id) initWithValue:(double)value;

@end

这篇关于帮助与理解C#代码移植到Objective-C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆