其实都差不多......
语言 | 方法调用 | 变量调用 |
---|---|---|
objective-c | [self funA:5] | self.var |
swift | self.funA(para: 5) | self.var |
c++ | this->funA(5) | this->var |
java | this.funA(5) | this.var |
js | this.funA(5) | this.var |
python | funA(var) | var = 1 |
php | $this->funA(5) | $this->var |
语言 | 变量定义 | 数组定义 |
---|---|---|
objective-c | int a=1 | int ary[] = {1, 2, 3, 4, 5} |
swift | var a = 10 | var ary = [1, 2, 3, 4, 5] |
c++ | int a = 10 | int ary[] = {1, 2, 3, 4, 5} |
java | int a = 10 | int[] ary = {1, 2, 3, 4, 5} |
python | a = 10 | ary = [1, 2, 3, 4, 5] |
php | $a = 10 | $ary = array(1, 2, 3, 4, 5); |
类定义使用
oc:
@interface MyClass : NSObject
@property (nonatomic, assign) int intProperty;
- (void)printSomething:(NSString *)something;
@end
// MyClass.m 文件
#import "MyClass.h"
@implementation MyClass
- (void)printSomething:(NSString *)something {
NSLog(@"%@", something);
}
@end
// 使用MyClass
MyClass *myObject = [[MyClass alloc] init];
myObject.intProperty = 2;
[myObject printSomething:@"Hello, World!"];
NSLog(@"%d", myObject.intProperty);
swift:
class MyClass {
let intProperty: Int = 2
func printSomething(_ something: String) {
print(something)
}
}
let myObject = MyClass()
myObject.printSomething("Hello, World!")
print(myObject.intProperty)
c++:
#include <iostream>
#include <string>
class MyClass {
public:
int intProperty = 2;
void printSomething(std::string something) {
std::cout << something << std::endl;
}
};
int main() {
MyClass myObject;
myObject.printSomething("Hello, World!");
std::cout << myObject.intProperty << std::endl;
return 0;
}
java:
public class MyClass {
public int intProperty = 2;
public void printSomething(String something) {
System.out.println(something);
}
public static void main(String[] args) {
MyClass myObject = new MyClass();
myObject.printSomething("Hello, World!"); // 输出 "Hello, World!"
System.out.println(myObject.intProperty); // 输出 "2"
}
}
js:
class MyClass {
constructor() {
this.intProperty = 2;
}
printSomething(something) {
console.log(something);
}
}
let myObject = new MyClass();
myObject.printSomething("Hello, World!");
console.log(myObject.intProperty);