L02_基本数据类型



sbytebyteshortushortintuintlongulong8个是整数,他们之间的区别就是表示氛围不一样,而对于范围不一样的根本原因是类型在内存中的存储不同。

C#常用基本数据类型的名称——含义——范围——默认值


基本数据类型纠错

1sbyte类型是有赋值范围的,所以超出赋值会报错

using System;

namespace Lesson05 {
	class MainClass {
		public static void Main (string[] args) {
			/* 整数类型 */
			// 声明的变量赋值后不能超过sbyte的范围
			sbyte a = 4;
			Console.WriteLine (a);
			byte b = 5;
			Console.WriteLine (b);
			// 有符号短整型
			short c = 4;
			Console.WriteLine (c);
			// 无符号短整型
			ushort d = 5;
			Console.WriteLine (d);
			// 整型
			int e = 4;
			Console.WriteLine (e);
			uint f = 6;
			Console.WriteLine (f);
			// 长整形
			long g = 6;
			Console.WriteLine (g);
			ulong h = 77;
			Console.WriteLine (h);

			/* 小数类型 */
			// 单精度浮点数
			float z = 4.56f;
			Console.WriteLine (z);
			// 双精度浮点数 
			double x = 4.56;
			Console.WriteLine (x);

			/* 字符串类型 */
			// 字符串类型的数不能参与运算
			string name = "老王";
			Console.WriteLine (name);

			/* 布尔类型 逻辑运算:只有true或false两个值!*/
			bool u = true;   // 真
			u = false;		 // 假
			Console.WriteLine (u);

			// int类型变量会在内存中占用 4 字节空间(32位)
			// sizeof用来获取每种类型所占用空间大小的字节数
			Console.WriteLine (sizeof(int));
			// short类型变量会在内存中占用 2 字节空间(16位)
			Console.WriteLine (sizeof(short));
		}
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值