当前位置: 首页>>代码示例>>C#>>正文


C# Student.GetType方法代码示例

本文整理汇总了C#中Student.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Student.GetType方法的具体用法?C# Student.GetType怎么用?C# Student.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Student的用法示例。


在下文中一共展示了Student.GetType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    static void Main()
    {
        Student s1 = new Student("Callie");

        Console.WriteLine("type is "+s1.GetType().FullName);

        if ( s1.GetType() == typeof(Student) ) {
          Console.WriteLine(s1.Name+" is a Student");
        }

        if ( s1 is Student) {
          Console.WriteLine(s1.Name+" is a Student");
        }
    }
开发者ID:guyuefeng,项目名称:aspnet-sample,代码行数:14,代码来源:ObjectIdentity.cs

示例2: Main

        static void Main(string[] args)
        {
            var persoon = new Student();
            persoon.VerhoogDeLeeftijd();
            persoon.VerhoogDeLeeftijd();
            persoon.VerhoogDeLeeftijd();
            persoon.VerhoogDeLeeftijd();

            var field = persoon.GetType().GetField("_leeftijd", BindingFlags.NonPublic | BindingFlags.Instance);
            var value = field.GetValue(persoon);

            Console.WriteLine(value);

            Persoon p2 = new Persoon(123);
            foreach (var f in p2.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
            {
                object v = f.GetValue(persoon);
                f.SetValue(p2, v);
            }

            Console.WriteLine(p2);

            Persoon p3 = new Persoon(23123);
            p3.Reinitialize();

            MyDemoStruct st = new MyDemoStruct(4);
            st.Reinitialize();

            Console.WriteLine(st.Data);
        }
开发者ID:riezebosch,项目名称:cnetin1,代码行数:30,代码来源:Program.cs

示例3: Comparison

        /// <summary>
        ///     Comparisons the specified a.
        /// </summary>
        /// <param name="a">a.</param>
        /// <param name="b">The b.</param>
        /// <returns></returns>
        public static int Comparison(Student a, Student b)
        {
            // The Students Do not have the same Name
            // Sort by name
            if (!a.Name.Equals(b.Name)) return a.CompareTo(b);

            // The students have the same type
            return a.ToString().Equals(b.ToString())
                ? a.Number.CompareTo(b.Number)
                : TypeValue(a.GetType()).CompareTo(TypeValue(b.GetType()));
        }
开发者ID:davericher,项目名称:cst8256,代码行数:17,代码来源:StudentSorter.cs

示例4: constructTest

    private void constructTest()
    {
        Student st = new Student();
        Type tp = st.GetType();
        Debug.Log(tp);
        ConstructorInfo[] ci = tp.GetConstructors();    //获取类的所有构造函数
        int i = 1;
        foreach (ConstructorInfo c in ci) //遍历构造函数
        {
            ParameterInfo[] ps = c.GetParameters();    //取出每个构造函数的所有参数
            foreach (ParameterInfo pi in ps)   //遍历该构造函数的所有参数
            {
                Debug.Log(i + "" + pi.ParameterType.ToString());
                Debug.Log(i + "" + pi.Name);
            }
            i++;
        }

        Type[] pt = new Type[2];
        pt[0] = typeof(string);
        pt[1] = typeof(int);
        ConstructorInfo cmethod = tp.GetConstructor(pt); //根据参数类型获取构造函数

        object[] obj = new object[2] { "sen", 23 }; //构造Object数组,作为构造函数的输入参数
        object newStudent = cmethod.Invoke(obj); //调用构造函数生成对象
        ((Student)newStudent).setId(32);

        //方法二
        object[] obj2 = new object[1] { "qing" };
        //用Activator的CreateInstance静态方法,生成新对象
        object newStudent2 = Activator.CreateInstance(tp, obj2);
        ((Student)newStudent2).setId(37);

        object obj3 = Activator.CreateInstance(tp);
        //取得ID字段
        FieldInfo fi = tp.GetField("_age");
        fi.SetValue(obj3, 25);

        //取得MyName属性
        PropertyInfo pi1 = tp.GetProperty("Sex");
        pi1.SetValue(obj3, 1, null);

        //取得show方法
        MethodInfo mi = tp.GetMethod("show");
        //调用show方法
        mi.Invoke(obj3, null);
    }
开发者ID:qingsen,项目名称:notes,代码行数:47,代码来源:ReflectTest.cs

示例5: Main

        static void Main(string[] args)
        {
            Osoba osoba = new Osoba();
            string s = osoba.DajOib();
            bool isto = osoba.Equals(new Osoba());
            int hash = osoba.GetHashCode();
            System.Type t1 = osoba.GetType();
            string s1 = osoba.ToString();

            Osoba osobaStudent = new Student();
            string os = osobaStudent.DajOib();
            bool sisto = osobaStudent.Equals(new Osoba());
            int shash = osobaStudent.GetHashCode();
            System.Type st1 = osobaStudent.GetType();
            string s2 = osobaStudent.ToString();

            //Student stud = new Osoba(); //ne moze
        }
开发者ID:domi992,项目名称:02-TipoviOperatori,代码行数:18,代码来源:Program.cs

示例6: Main

        static void Main(string[] args)
        {
            Osoba osoba = new Osoba();
            osoba.ToString();
            osoba.DajOib();
            osoba.GetHashCode();
            osoba.GetType();
            osoba.Equals( "545451454");

            Osoba osobaStudent = new Student();
            osobaStudent.DajOib();
            osobaStudent.Equals(5);
            osobaStudent.GetHashCode();
            osobaStudent.GetType();
            osobaStudent.ToString();

            //Student studos = new Osoba(); moramo izvesti eksplicitni cast
        }
开发者ID:josipjuretic,项目名称:02-TipoviOperatori,代码行数:18,代码来源:Program.cs

示例7: CustomSort

        public static int CustomSort(Student a, Student b)
        {
            // If the students have different names, sort alphabetically
            if (a.Name.Equals(b.Name) == false) return a.CompareTo(b);

            // If the students have the same name
            if (a.Name.Equals(b.Name))
            {
                // If students have the same type
                return a.ToString().Equals(b.ToString())
                    // Sort by student number
                    ? a.Number.CompareTo(b.Number)
                    // Sort by student type
                    : GetStudentTypeValue(a.GetType()).CompareTo(GetStudentTypeValue(b.GetType()));
            }

            return -1;
        }
开发者ID:egnsh93,项目名称:CST8256,代码行数:18,代码来源:StudentComparer.cs

示例8: reflectTest

    private void reflectTest()
    {
        //string n = "grayworm";
        //Type t = n.GetType();
        //Debug.Log(t);
        //int i = 1;
        //foreach (MemberInfo mi in t.GetMembers())
        //{
        //    Debug.Log(i+""+mi.MemberType); //MemberTypes: Method, Field...
        //    Debug.Log(i + "" + mi.Name);
        //    i++;
        //}

        //查看类中的属性
        Debug.Log("GetProperties");
        Student st = new Student();
        Type tp = st.GetType();
        PropertyInfo[] pis = tp.GetProperties(); //属性 get,set
        int p = 1;
        foreach (PropertyInfo pi in pis)
        {
            Debug.Log(pi.Name);
            p++;
        }

        Debug.Log("GetMethods");
        int m = 1;
        MethodInfo[] mis = tp.GetMethods();  //public方法
        foreach (MethodInfo mi in mis)
        {
            Debug.Log(m + "" + mi.ReturnType);
            Debug.Log(m + "" + mi.Name);
            m++;
        }

        Debug.Log("GetFields");
        int f = 1;
        FieldInfo[] fis = tp.GetFields();  //public字段
        foreach (FieldInfo fi in fis)
        {
            Debug.Log(f + "" + fi.Name);
            f++;
        }
    }
开发者ID:qingsen,项目名称:notes,代码行数:44,代码来源:ReflectTest.cs


注:本文中的Student.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。