Unity开发基础——基本数据类型学习笔记

来源:互联网 发布:数据库死锁解决 编辑:程序博客网 时间:2024/05/16 15:54

Unity开发基础基本数据类型学习笔记

sbyte、byte、short、ushort、int、uint、long、ulong8个是整数,他们之间的区别就是表示氛围不一样,而对于范围不一样的根本原因是类型在内存中的存储不同。

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

 

蓝鸥Unity开发基础——基本数据类型纠错

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

 

2、float赋值之后需要加上f ,如果不加f会出现报错!

 

蓝鸥Unity开发基础——基本数据类型练习题

 

using System;

namespace Lesson05
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            //整数类型赋值

            sbyte a = 120;
            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);
          
        }
    }
}

在通过在CSDN学院搜索"宋晓波"观看C#入门基础课程




0 0
原创粉丝点击