《C#中-typeof和double小数(4页).doc》由会员分享,可在线阅读,更多相关《C#中-typeof和double小数(4页).doc(4页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、-C#中-typeof和double小数-第 4 页double x=5.1e3;/ 5.1乘以10的3次方。x就是5100/注: 5.1e+3=5.1e3=5.1e03=5.1e+03double y=5.1e-3;/ 5.1乘以10的-3次方。y就是0.0051double z=5.1e0;/ 5.1乘以10的0次方。z就是5.1Type t = typeof(string);Type t = typeof(System.String);Type 是抽象类, typeof(类名称) 返回的是继承自Type 的RuntimeType比如自定义类Studentpublic class Stud
2、entpublic void Method()Student s=new Student();Console.WriteLine(typeof(Student).ToString();/typeof(s)是错误的C# typeof()实例详解 typeof(C# 参考)用于获取类型的 System.Type 对象。typeof 表达式采用以下形式:System.Type type = typeof(int);备注 若要获取表达式的运行时类型,可以使用 .NET Framework 方法 GetType,如下所示:int i = 0;System.Type type = i.GetType();
3、typeof 运算符也能用于公开的泛型类型。具有不止一个类型参数的类型的规范中必须有适当数量的逗号。不能重载 typeof 运算符。view sourceprint?示例 / cs_operator_typeof.cs 03using System; 04using System.Reflection; 05public class SampleClass 06 07public int sampleMember; 08public void SampleMethod() 09static void Main() 10 11Type t = typeof(SampleClass); 12/ A
4、lternatively, you could use 13/ SampleClass obj = new SampleClass(); 14/ Type t = obj.GetType(); 15Console.WriteLine(Methods:); 16MethodInfo methodInfo = t.GetMethods(); 17foreach (MethodInfo mInfo in methodInfo) 18Console.WriteLine(mInfo.ToString(); 19Console.WriteLine(Members:); 20MemberInfo membe
5、rInfo = t.GetMembers(); 21foreach (MemberInfo mInfo in memberInfo) 22Console.WriteLine(mInfo.ToString(); 23 24 25输出 26Methods: 27Void SampleMethod() 28System.Type GetType() 29System.String ToString() 30Boolean Equals(System.Object) 31Int32 GetHashCode() 32Members: 33Void SampleMethod() 34System.Type
6、 GetType() 35System.String ToString() 36Boolean Equals(System.Object) 37Int32 GetHashCode() 38Void .ctor() 39Int32 sampleMember 40此示例使用 GetType 方法确定用来包含数值计算的结果的类型。这取决于结果数字的存储要求。 4142/ cs_operator_typeof2.cs 43using System; 44class GetTypeTest 45 46static void Main() 47 48int radius = 3; 49Console.WriteLine(Area = 0, radius * radius * Math.PI); 50Console.WriteLine(The type is 0, 51(radius * radius * Math.PI).GetType() 52); 53 54 输出 Area = 28.2743338823081 57The type is System.Double