您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 信息化管理 > C#中-typeof和double小数
doublex=5.1e3;//5.1乘以10的3次方。x就是5100//注:5.1e+3=5.1e3=5.1e03=5.1e+03doubley=5.1e-3;//5.1乘以10的-3次方。y就是0.0051doublez=5.1e0;//5.1乘以10的0次方。z就是5.1Typet=typeof(string);Typet=typeof(System.String);Type是抽象类,typeof(类名称)返回的是继承自Type的RuntimeType比如自定义类StudentpublicclassStudent{publicvoidMethod(){Students=newStudent();Console.WriteLine(typeof(Student).ToString());//typeof(s)是错误的}}C#typeof()实例详解typeof(C#参考)用于获取类型的System.Type对象。typeof表达式采用以下形式:System.Typetype=typeof(int);备注若要获取表达式的运行时类型,可以使用.NETFramework方法GetType,如下所示:inti=0;System.Typetype=i.GetType();typeof运算符也能用于公开的泛型类型。具有不止一个类型参数的类型的规范中必须有适当数量的逗号。不能重载typeof运算符。viewsourceprint?示例//cs_operator_typeof.cs03usingSystem;04usingSystem.Reflection;05publicclassSampleClass06{07publicintsampleMember;08publicvoidSampleMethod(){}09staticvoidMain()10{11Typet=typeof(SampleClass);12//Alternatively,youcoulduse13//SampleClassobj=newSampleClass();14//Typet=obj.GetType();15Console.WriteLine(Methods:);16MethodInfo[]methodInfo=t.GetMethods();17foreach(MethodInfomInfoinmethodInfo)18Console.WriteLine(mInfo.ToString());19Console.WriteLine(Members:);20MemberInfo[]memberInfo=t.GetMembers();21foreach(MemberInfomInfoinmemberInfo)22Console.WriteLine(mInfo.ToString());23}24}25输出26Methods:27VoidSampleMethod()28System.TypeGetType()29System.StringToString()30BooleanEquals(System.Object)31Int32GetHashCode()32Members:33VoidSampleMethod()34System.TypeGetType()35System.StringToString()36BooleanEquals(System.Object)37Int32GetHashCode()38Void.ctor()39Int32sampleMember40此示例使用GetType方法确定用来包含数值计算的结果的类型。这取决于结果数字的存储要求。4142//cs_operator_typeof2.cs43usingSystem;44classGetTypeTest45{46staticvoidMain()47{48intradius=3;49Console.WriteLine(Area={0},radius*radius*Math.PI);50Console.WriteLine(Thetypeis{0},51(radius*radius*Math.PI).GetType()52);53}54}输出Area=28.274333882308157ThetypeisSystem.Double
本文标题:C#中-typeof和double小数
链接地址:https://www.777doc.com/doc-4702172 .html