C# - This

  1. 「this」即這個物件的
  2. this 是一種 reference type 的變數,是一個指向自己物件的物件變數
  3. this 這個變數會隨物件建立的時候就宣告
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Student
{
public int StudentID;
public string Name;
public int Grade;
public int height;
public Student(int studentID, string name, int grade,int height)
{
StudentID = studentID;
Name = name;
Grade = grade;
this.height = height; // this.height => 這個物件的 height
}

}

Powered by Hexo and Hexo-theme-hiker

Copyright © 2013 - 2020 CYC'S BLOG All Rights Reserved.

UV : | PV :