using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class Main : MonoBehaviour{
private bool boolVal;
private byte byteVal;
private double doubleVal;
private float floatVal;
private int intVal;
private long longVal;
private short shortVal;
private uint uintVal;
private char charVal;
private string stringVal;
private Vector2 vector2Val;
private Vector3 vector3Val;
private Man classVal;
private CustomData structVal; private bool? boolVal2;
private float? floatVal2;
private int? intVal2;
private System.Nullable<int> intVal3;
private Vector2? vector2Val2;
private Vector2? vector2Val3=null;
private CustomData? structVal2=null; private void Start() {
Debug.LogFormat("boolVal:{0}",boolVal);//output:boolVal:False
Debug.LogFormat("byteVal:{0}",byteVal);//output:byteVal:0
Debug.LogFormat("doubleVal:{0}",doubleVal);//output:doubleVal:0
Debug.LogFormat("floatVal:{0}",floatVal);//output:floatVal:0
Debug.LogFormat("intVal:{0}",intVal);//output:intVal:0
Debug.LogFormat("longVal:{0}",longVal);//output:longVal:0
Debug.LogFormat("{0}",shortVal);//output:shortVal:0
Debug.LogFormat("uintVal:{0}",uintVal);//output:uintVal:0
Debug.LogFormat("charVal:{0},{1}",charVal,charVal=='\0');//output:charVal:
if(charVal=='\0')Debug.Log("True");//output:True
Debug.LogFormat("vector2Val:{0},{1}",vector2Val,vector2Val==Vector2.zero);//output:vector2Val:(0.0, 0.0),True
Debug.LogFormat("vector3Val:{0},{1}",vector3Val,vector3Val==Vector3.zero);//output:vector3Val:(0.0, 0.0, 0.0),True
Debug.LogFormat("classVal:{0},{1}",classVal,classVal==null);//output:classVal:,True
Debug.LogFormat("structVal:{0}",structVal);//output:structVal:CustomData Debug.LogFormat("boolVal2:{0}",boolVal2==null);//output:boolVal2:True
Debug.LogFormat("floatVal2:{0}",floatVal2==null);//output:floatVal2:True
Debug.LogFormat("intVal2:{0}",intVal2==null);//output:intVal2:True
Debug.LogFormat("intVal3:{0}",intVal3==null);//output:intVal3:True
Debug.LogFormat("vector2Val2:{0}",vector2Val2==null);//output:vector2Val2:True
Debug.LogFormat("vector2Val3:{0}",vector2Val3==null);//output:vector2Val3:True
Debug.LogFormat("structVal2:{0}",structVal2==null);//output:structVal2:True
}
} public class Man{ }
public struct CustomData{
public int ID;
}

//更多C#数据类型参考: https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/reference-tables-for-types

//默认值表:https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/default-values-table

C#、Unity 数据类型的默认值的更多相关文章

  1. java 8种基本数据类型的默认值及所占字节数

    通过一段代码来测试一下 8种基本数据类型的默认值 package dierge; public class Ceshi { int a; double b; boolean c; char d; fl ...

  2. java中8种数据类型和默认值所占字节数

    java 8种基本数据类型的默认值及所占字节数 通过一段代码来测试一下 8种基本数据类型的默认值 1 package dierge; 2 3 public class Ceshi { 4 int a; ...

  3. java 常用基本数据类型的默认值

    在使用基本数据类型作为类成员的时候,有时只初始化了而没有给变量赋值,那么此时,java会给你的变量赋一个默认初始值. boolean        false char              '/ ...

  4. go中基本数据类型的默认值

    代码 // 基本数据类型(整型,浮点型,字符串型,布尔型)的默认值 package main import ( "fmt" ) func main() { var a int va ...

  5. golang的数据类型之基本数据类型的默认值和转换

    默认值: 整型的默认值:0 浮点型的默认值:0字符串的默认值:""   //空布尔类型的默认值:false package mainimport "fmt" f ...

  6. prop不同数据类型设置默认值

    vue prop 会接收不同的数据类型,这里列出了 常用的数据类型的设置默认值的写法,其中包含: Number, String, Boolean, Array,  Function, Object   ...

  7. (转载)JAVA中八种基本数据类型的默认值

    原文链接: http://simon-c.iteye.com/blog/1016031 引用 For type byte, the default value is zero, that is, th ...

  8. Java基础数据类型的默认值

    1.整数类型(byte.short.int.long)的基本类型变量的默认值为0. 2.单精度浮点型(float)的基本类型变量的默认值为0.0f. 3.双精度浮点型(double)的基本类型变量的默 ...

  9. mysql设置datetime默认值为now

    mysql设置datetime默认值为now MYSQL-TIMESTAMP数据类型的默认值与自动更新问题 http://blog.csdn.net/scogeek/article/details/5 ...

随机推荐

  1. python day27--常用模块 time,random,os,序列化

    一.time模块 %y 两位数的年份表示(00-99) %Y 四位数的年份表示(000-9999) %m 月份(01-12) %d 月内中的一天(0-31) %H 24小时制小时数(0-23) %I ...

  2. 新建一个self hosted Owin+ SignalR Project(1)

    OWIN是Open Web Server Interface for .Net 的首字母缩写,他的定义如下: OWIN在.NET Web Server 与Web Application之间定义了一套标 ...

  3. erlang工作总结

    总结下自己在做erlang的经验 1.不管什么样的情况下,一定要关注好函数的返回值再来使用,不知道返回值盲目的使用的话,不仅不能达到目标,而且不存在代码/报错提醒.得不偿失. 2.构思好自己的想法,定 ...

  4. Python 使用sys.exc_info自己捕获异常详细信息

    一般程序中,我们需要对异常进行捕获来保证程序的健壮.但是debug的时候,我们可能需要异常的详细信息,这时可以使用sys.exec_info来处理: import traceback import s ...

  5. 关于anguar2微信支付问题

    前端一直都是用angular2做的 但是在做支付时,很头痛 ,支付总是失败,但后没有办法只能是跳转到一个其它的页面进行支付,这也算实现了,但是觉得不好,支付完了以要重新跳回系统,怎么解决??????? ...

  6. mvn package出现No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK

    配置java环境变量时偷懒,没有定义%JAVA_HOME%,应该先定义这个变量,然后在path中新建%JAVA_HOME%\bin和%JAVA_HOME%\jre\bin

  7. Centos7 firewall开放3306端口

    目录 Centos7 firewall开放3306端口 1. 查看防火墙状态 2. 关闭防火墙firewall 3. 关闭防火墙firewall后开启 4. 开启端口 5. 重启防火墙 6. 常用命令 ...

  8. robot framework程序运行过程中,遇到点击事件之后,未出现点击之后的效果(求解)

    1.click Element操作,在实际过程中偶然会出现,日志显示已点击成功,但是实际自动化页面,没有点击成功之后的操作 现象: 现象描述:程序执行到点击侧边栏的[人员信息]之后,日志显示已经点击成 ...

  9. Java面试题 OOAD & UML+XML+SQL+JDBC & Hibernate

    二.OOA/D 与UML 部分:(共6 题:基础2 道,中等难度4 道) 96.UML 是什么?常用的几种图?[基础] 答:UML 是标准建模语言:常用图包括:用例图,静态图(包括类图.对象图和包图) ...

  10. PostgreSQL Oracle 兼容性之 - sys_guid()

    Oracle 使用sys_guid()用来产生UUID值.  在PostgreSQL中有类似的函数,需要安装uuid-ossp插件.  如果用户不想修改代码,还是需要使用sys_guid()函数的话, ...