zoukankan      html  css  js  c++  java
  • C# IsAssignableFrom & IsInstanceOfType & IsSubclassOf & Is

    直观测试代码如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    public partial class NaviControl : UserControl, ITestControl
    {
        public NaviControl()
        {
            InitializeComponent();
            Load += NaviControl_Load;
        }
     
        private void NaviControl_Load(object sender, EventArgs e)
        {
            Debug.Print($"Base.IsAssignableFrom:");
            Debug.Print($"{typeof(UserControl).IsAssignableFrom(this.GetType())}");//True
            Debug.Print($"{typeof(ITestControl).IsAssignableFrom(this.GetType())}");//True
            Debug.Print($"This.IsAssignableFrom:");
            Debug.Print($"{this.GetType().IsAssignableFrom(typeof(UserControl))}");//False
            Debug.Print($"{this.GetType().IsAssignableFrom(typeof(ITestControl))}");//False
            Debug.Print($"Base.IsInstanceOfType:");
            Debug.Print($"{typeof(UserControl).IsInstanceOfType(this)}");//True
            Debug.Print($"{typeof(ITestControl).IsInstanceOfType(this)}");//True
            Debug.Print($"This.IsSubclassOf:");
            Debug.Print($"{this.GetType().IsSubclassOf(typeof(UserControl))}");//True
            Debug.Print($"{this.GetType().IsSubclassOf(typeof(ITestControl))}");//False
            Debug.Print($"This.Is:");
            Debug.Print($"{(this is UserControl)}");//True
            Debug.Print($"{(this is ITestControl)}");//True
     
     
        }
    }

      

  • 相关阅读:
    用ruby抓取网页
    [转] 从项目管理角度看敏捷开发
    ruby学习笔记(9)
    [转] 从项目管理角度看敏捷开发
    ruby学习笔记(8)
    ruby学习笔记(7)
    [转] 什么是敏捷开发
    netbeans tomcat
    maven
    jersey
  • 原文地址:https://www.cnblogs.com/linybo/p/13258965.html
Copyright © 2011-2022 走看看