zoukankan      html  css  js  c++  java
  • C#常见函数

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace 反射常用函数
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Student是否能为Person类型赋值");
                bool bl = typeof(Person).IsAssignableFrom(typeof(Student));//True
                Console.WriteLine(bl);
    
                Student s = new Student();
                Person p = new Person();
                //IsInstanceOfType(object o)判断对象o是否为当前类的实例(当前类可以是o的类、父类、接口)
                //子类可赋值为父类bool bl1 = typeof(Person).IsInstanceOfType(s);//True
                //bool bl1 = typeof(I1).IsInstanceOfType(s);//True
                //bool bl1 = IsInstanceOfType(s);//True
    
                //判断当前类是否为类Person的子类
                //bool bl1 = s.GetType().IsSubclassOf(typeof(Person));
    
                //判断是否为抽象类
                bool bl1 = typeof(Person).IsAbstract;
    
                Console.WriteLine(bl1);
    
                Console.ReadKey();
            }
        }
    
        class Person
        { }
    
        class Student:Person,I1
        {
    
            public void Test()
            {
                throw new NotImplementedException();
            }
        }
    
        interface I1
        {
            void Test();
        }
    }

  • 相关阅读:
    sendmessage参数
    combobox添加选项
    sql数据库时间转换convert
    Javascript知识四(DOM)
    Javascript知识三
    JavaScript知识(二)
    JavaScript知识(一)
    三层架构
    ADO知识的运用二(Day 28)
    SQL知识三(Day 27)
  • 原文地址:https://www.cnblogs.com/my-cat/p/7976641.html
Copyright © 2011-2022 走看看