C# 类型 byte,int,short,long,decimal,double,float

本文详细介绍了C#中的基本数据类型,包括byte、int、short、long、decimal、double和float等,并通过实例展示了这些类型的使用方法及特点。

C# 类型 byte,int,short,long,decimal,double,float

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代码:

 

ExpandedBlockStart.gif 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();
        }
    }
}

 

下载完整程序包

0
0
(请您对文章做出评价)
posted @ 2009-01-06 14:59  无尽思绪 阅读(900)  评论(0)   编辑  收藏  网摘 所属分类:  .Net(c#,asp.net)


转载于:https://www.cnblogs.com/vhtt/archive/2009/10/07/1578627.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值