1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 namespace ConsoleApp1
6 {
7 public class Student
8 {
9 public Student(string firstName,string lastName)
10 {
11 FirstName = firstName;
12 LastName = lastName;
13 }
14
15 public int? Id { get; set; }
16 public string TestName { get; set; }
17
18 /// <summary>
19 /// 只能經過構造函數賦值
20 /// </summary>
21 public string FirstName { get; }
22 public string LastName { get; }
23
24 /// <summary>
25 /// FullName1 與 FullName2 功能相同
26 /// </summary>
27 public string FullName1
28 {
29 get
30 {
31 return string.Format("{0}-{1}", this.FirstName, this.LastName);
32 }
33 }
34
35 public string FullName2=> string.Format("{0}-{1}", this.FirstName, this.LastName);//念 goes to
36
37 public void Show()
38 {
39 Console.WriteLine(string.Format("FullName1:{0}",FullName1));
40 Console.WriteLine(string.Format("FullName2:{0}", FullName2));
41 }
42
43 /// <summary>
44 /// 方法A (方法A與方法B功能相同)
45 /// </summary>
46 /// <returns></returns>
47 public override string ToString() => string.Format("我是方法:{0}-{1}", this.FirstName, this.LastName);//念 goes to
48 /// <summary>
49 /// 方法B
50 /// </summary>
51 /// <returns></returns>
52 //public override string ToString()
53 //{
54 // return string.Format("我是方法:{0}-{1}", this.FirstName, this.LastName);
55 //}
56
57 }
58 }