namespace ConsoleApp_UseExtendWays
{
class Program
{
static void Main(string[] args)
{
Student s = new Student();
Console.WriteLine(s.GetSexString());
Console.WriteLine(s.GetAge());
Console.ReadKey();
}
}
public static class StudentExtension
{
public static string GetSexString(this Student argStudent)//扩展方法 this 扩展类型
{
return argStudent.GetSex() == true ? "男" : "女";
}

public static int GetAge(this Student ss)
{
return ss.Age;
}
}
public class Student
{
public bool GetSex()
{
return false;
}

public int Age = 12;
}

//public static class StudentConverter
//{
// public static string GetSexString(Student argStudent)
// {
// return argStudent.GetSex() == true ? "男" : "女";
// }
//}
}

相关文章:

  • 2021-12-16
  • 2021-07-18
  • 2021-08-14
  • 2021-11-13
  • 2021-11-13
  • 2021-04-22
  • 2021-08-06
  • 2021-09-01
猜你喜欢
  • 2018-12-11
  • 2021-11-13
  • 2021-12-15
  • 2021-09-16
  • 2019-03-05
  • 2021-11-05
  • 2021-09-01
  • 2021-09-01
相关资源
相似解决方案