C# 类型 byte,int,short,long,decimal,double,float
//创建控制台程序文件:myInt.cs
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSType
{
public class myInt
{
public myInt()
{
//byte类型从0 -> 255。
byte xb = 1; //整型1隐式转换成byte类型.如果整数大于255,则产生异常(错误)
Console.WriteLine(xb.GetType());
// output System.Byte
//doesn't work
//byte xb1 = 256;
int xi = 1;
Console.WriteLine(xi.GetType());
//output System.Int32
short xs = 2;
Console.WriteLine(xs.GetType());
//output System.Int16
long xl = 3;
Console.WriteLine(xl.GetType());
//output System.Int64
//doesn't work , ushort,uint,ulong表示无符号的short,int,long,普通点说,就是没有负数,只有正数和0
//ushort xus = -1;
ushort xus = 1;
Console.WriteLine(xus.GetType());
//output System.UInt16
uint xui = 2;
Console.WriteLine(xui.GetType());
//output System.UInt32
ulong xul = 3;
Console.WriteLine(xul.GetType());
//output System.UInt64
decimal xd = 2; //整型2隐式转换成decimal类型
Console.WriteLine(xd.GetType());
//output System.Decimal
Console.WriteLine(xd);
float xf = 2f;
Console.WriteLine(xf.GetType());
//output System.Single -- 单精度
double xdo = 2; // 整型2隐式转换成double类型
Console.WriteLine(xdo.GetType());
//output System.Double -- 双精度
Console.WriteLine(xdo);
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSType
{
public class myInt
{
public myInt()
{
//byte类型从0 -> 255。
byte xb = 1; //整型1隐式转换成byte类型.如果整数大于255,则产生异常(错误)
Console.WriteLine(xb.GetType());
// output System.Byte
//doesn't work
//byte xb1 = 256;
int xi = 1;
Console.WriteLine(xi.GetType());
//output System.Int32
short xs = 2;
Console.WriteLine(xs.GetType());
//output System.Int16
long xl = 3;
Console.WriteLine(xl.GetType());
//output System.Int64
//doesn't work , ushort,uint,ulong表示无符号的short,int,long,普通点说,就是没有负数,只有正数和0
//ushort xus = -1;
ushort xus = 1;
Console.WriteLine(xus.GetType());
//output System.UInt16
uint xui = 2;
Console.WriteLine(xui.GetType());
//output System.UInt32
ulong xul = 3;
Console.WriteLine(xul.GetType());
//output System.UInt64
decimal xd = 2; //整型2隐式转换成decimal类型
Console.WriteLine(xd.GetType());
//output System.Decimal
Console.WriteLine(xd);
float xf = 2f;
Console.WriteLine(xf.GetType());
//output System.Single -- 单精度
double xdo = 2; // 整型2隐式转换成double类型
Console.WriteLine(xdo.GetType());
//output System.Double -- 双精度
Console.WriteLine(xdo);
Console.ReadLine();
}
}
}
program.cs代码:
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSType
{
class Program
{
static void Main(string[] args)
{
//new myBool();
//new MyType();
new myInt();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSType
{
class Program
{
static void Main(string[] args)
{
//new myBool();
//new MyType();
new myInt();
}
}
}