在c#编程中,this 引用类的当前实例的关键字。在C#中,该关键字有三种主要用法。
让无涯教程看一下this关键字在C#中引用当前类的字段的示例。
链接:https://www.learnfk.comhttps://www.learnfk.com/csharp/c-sharp-this.html
来源:LearnFk无涯教程网
using System; public class Employee { public int id; public String name; public float salary; public Employee(int id, String name,float salary) { this.id = id; this.name = name; this.salary = salary; } public void display() { Console.WriteLine(id + " " + name+" "+salary); } } class TestEmployee{ public static void Main(string[] args) { Employee e1 = new Employee(101, "Sonoo", 890000f); Employee e2 = new Employee(102, "Mahesh", 490000f); e1.display(); e2.display(); } }
输出:
101 Sonoo 890000 102 Mahesh 490000
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)