c#与ts类对象
# ts类
class Person {
Name: string;
Age: number;
sayHello() {
console.log(`Hello, my name is ${this.Name} and I am ${this.Age} years old.`);
}
}
let person = new Person();
person.Name = "John";
person.Age = 30;
person.sayHello();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# C#类
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public void SayHello()
{
Console.WriteLine("Hello, my name is " + Name + " and I am " + Age + " years old.");
}
}
class Program
{
static void Main(string[] args)
{
Person person = new Person();
person.Name = "John";
person.Age = 30;
person.SayHello();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
编辑 (opens new window)
上次更新: 2024/08/09, 10:55:31