zoukankan      html  css  js  c++  java
  • 使用扩展方法(this 扩展类型)


    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 ? "男" : "女";
    // }
    //}
    }
  • 相关阅读:
    连通块问题
    线性数据结构
    NOIP2018总结
    原码反码补码详解
    一些常用的算法技巧总结
    骗分导论
    模板
    模板
    AcWing
    AcWing
  • 原文地址:https://www.cnblogs.com/jx270/p/3608938.html
Copyright © 2011-2022 走看看