zoukankan      html  css  js  c++  java
  • typeof运算符

    typeof运算符

    typeof运算符用于获取类型的System.Type对象。
    typeof(x)中的x,必须是具体的类名、类型名称等,不可以是变量名称。
    typeof运算符不能重载。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace UseTypeof
    {
    class Program
    {
    static void Main(string[] args)
    {
    //typeof运算符
    System.Type byteType = typeof(byte);
    Console.WriteLine("byte类型的对象是:{0}", byteType);
    System.Type sbyteType = typeof(sbyte);
    Console.WriteLine("sbyte类型的对象是:{0}", sbyteType);
    System.Type intType = typeof(int);
    Console.WriteLine("int类型的对象是:{0}",intType );
    System.Type uintType = typeof(uint);
    Console.WriteLine("uint类型的对象是:{0}", uintType);
    System.Type shortType = typeof(short);
    Console .WriteLine ("short类型的对象是:{0}",shortType );
    System.Type ushortType = typeof(ushort);
    Console.WriteLine("ushort类型的对象是:{0}", ushortType);
    System.Type longType = typeof(long);
    Console.WriteLine("long类型的对象是:{0}", longType);
    System.Type ulongType = typeof(ulong);
    Console.WriteLine("ulong类型的对象是:{0}", ulongType);
    System.Type charType = typeof(char);
    Console.WriteLine("char类型的对象是{0}", charType);
    System.Type stringType = typeof(string);
    Console.WriteLine("string类型的对象是:{0}", stringType);
    System.Type floatType = typeof(float);
    Console.WriteLine("float类型的对象是:{0}", floatType);
    System.Type doubleType = typeof(double);
    Console.WriteLine("double类型的对象是:{0}", doubleType);
    System.Type decimalType = typeof(decimal);
    Console.WriteLine("decimal类型的对象是:{0}", decimalType);
    System.Type boolType = typeof(Boolean);
    Console.WriteLine("bool类型的对象是:{0}", boolType);


    A a1 = new A();
    a1.Fun();
    a1.GetType();
    Console.WriteLine(a1.GetType());
    }
    }
    class A
    {
    public void Fun()
    {
    Console.WriteLine("Fun()");
    }
    }
    }

    /*

    Output:

    byte类型的对象是:System.Byte
    sbyte类型的对象是:System.SByte
    int类型的对象是:System.Int32
    uint类型的对象是:System.UInt32
    short类型的对象是:System.Int16
    ushort类型的对象是:System.UInt16
    long类型的对象是:System.Int64
    ulong类型的对象是:System.UInt64
    char类型的对象是System.Char
    string类型的对象是:System.String
    float类型的对象是:System.Single
    double类型的对象是:System.Double
    decimal类型的对象是:System.Decimal
    bool类型的对象是:System.Boolean
    Fun()
    UseTypeof.A

    */

  • 相关阅读:
    数据对拍
    学大伟业 Day 5 培训总结
    【luogu P3378 堆】 模板
    【luogu P1865 A % B Problem】 题解
    学大伟业 Day 4 培训总结
    【luogu P1082 同余方程】 题解
    诗一首
    【luogu P2251 质量检测】 题解
    【luogu P3865 ST表】 模板
    【luogu P1816 忠诚】 题解
  • 原文地址:https://www.cnblogs.com/melao2006/p/4239084.html
Copyright © 2011-2022 走看看