this关键字:
    1、代表当前类的对象。
    2、在类当中显示的调用本类的构造函数 :this

    1. using System;
    2. using System.Collections.Generic;
    3. using System.Text;
    4. namespace _051_面对对象初级_6_this关键字
    5. {
    6. class Student
    7. {
    8. public Student(string name, int age, char gender, int chinese, int math, int english)
    9. {
    10. this.Name = name;
    11. this.Age = age;
    12. this.Gender = gender;
    13. this.Chinese = chinese;
    14. this.Math = math;
    15. this.English = english;
    16. }
    17. public Student(string name, int chinese, int math, int english) : this(name, 0, ' ', 100, 100, 100)
    18. {
    19. //this.Name = name;
    20. //this.Chinese = chinese;
    21. //this.Math = math;
    22. //this.English = english;
    23. }
    24. private string _name;
    25. public string Name
    26. {
    27. get { return _name; }
    28. set { _name = value; }
    29. }
    30. private int _age;
    31. public int Age
    32. {
    33. get { return _age; }
    34. set
    35. {
    36. if (value < 0 || value > 100)
    37. {
    38. value = 0;
    39. }
    40. _age = value;
    41. }
    42. }
    43. private char _gender;
    44. public char Gender
    45. {
    46. get
    47. {
    48. if (_gender != '男' && _gender != '女')
    49. {
    50. return _gender = '×';
    51. }
    52. return _gender;
    53. }
    54. set { _gender = value; }
    55. }
    56. private int _chinese;
    57. public int Chinese
    58. {
    59. get { return _chinese; }
    60. set { _chinese = value; }
    61. }
    62. private int _math;
    63. public int Math
    64. {
    65. get { return _math; }
    66. set { _math = value; }
    67. }
    68. private int _english;
    69. public int English
    70. {
    71. get { return _english; }
    72. set { _english = value; }
    73. }
    74. public void SayHello()
    75. {
    76. Console.WriteLine("我叫{0},今天{1}岁了,是个{2}生", this.Name, this.Age, this.Gender);
    77. }
    78. public void ShouScore()
    79. {
    80. Console.WriteLine("我的总成绩是{0},平均成绩是{1}", (this.Chinese + this.Math + this.English), (this.Chinese + this.Math + this.English) / 3);
    81. }
    82. }
    83. }