Explore 100's Of Free Video Tutorials

Keep Learning, Keep Coding & Keep Sharing

sizeof, MinValue, MaxValue, Character Set

Notes:

I. C# sizeof operator : [Starts at: 01min:55sec]
II. Range of C# data types : [Starts at: 11min:16sec]
III. C# Character set : [Starts at: 18min:58sec]

I. C# sizeof operator : [Starts at: 01min:55sec]
C# sizeof operator is used to find the size of any value types in bytes.
Syntax:
int sizeof(value type)

Example Code:
using UnityEngine;
public class FirstScript : MonoBehaviour {
// Use this for initialization
void Start ()
{
// Size of data types
// Numeric data types
// 1. Signed data types
Debug.Log("Size of short datatype=" + sizeof(short) + " byte(s)"); // 2
Debug.Log("Size of int datatype=" + sizeof(int) + " byte(s)"); // 4
Debug.Log("Size of long datatype=" + sizeof(long) + " byte(s)"); //8

Debug.Log("Size of float datatype=" + sizeof(float) + " byte(s)"); // 4
Debug.Log("Size of double datatype=" + sizeof(double) + " byte(s)"); // 8

//2. Unsigned data types
Debug.Log("Size of byte datatype=" + sizeof(byte) + " byte(s)"); // 1
Debug.Log("Size of ushort datatype=" + sizeof(ushort) + " byte(s)"); // 2
Debug.Log("Size of uint datatype=" + sizeof(uint) + " byte(s)"); // 4
Debug.Log("Size of ulong datatype=" + sizeof(ulong) + " byte(s)"); //8

// Non numeric data types
Debug.Log("Size of bool datatype=" + sizeof(bool) + " byte(s)"); // 1
Debug.Log("Size of char datatype=" + sizeof(char) + " byte(s)"); // 2

}
}

II. Range of C# data types : [Starts at: 11min:16sec]
Syntax:
datatype.MinValue
datatype.MaxValue

Example Code:
using UnityEngine;
public class FirstScript : MonoBehaviour {
// Use this for initialization
void Start ()
{
//Min and Max values
Debug.Log("byte: Min Value="+ byte.MinValue +" Max Value=" + byte.MaxValue); // 0 to 255
Debug.Log("short: Min Value="+ short.MinValue +" Max Value=" + short.MaxValue); // -32768 to 32767
Debug.Log("ushort: Min Value="+ ushort.MinValue +" Max Value=" + ushort.MaxValue); // 0 to 65535
}
}

III. C# Character set : [Starts at: 18min:58sec]
C# supports ASCII and Unicode character sets

ASCII:
(American Standards Code for Information Interchange (7 bit code))
2 pow 7 = 255 characters

Unicode:
(Universal Code for representing most of the characters of almost every written languages present in the world (16 bit))
2 pow 16 = 65536 characters

Example Code:
using UnityEngine;
public class FirstScript : MonoBehaviour {
// Use this for initialization
void Start ()
{
// Character Set
// ASCII : American Standards Code For Information Interchange : 7 bits
// UNICODE : Universal Code : 16 bits
Debug.Log((int)'A'); // 65 : value of A in ASCII is 65
Debug.Log ('\u0041'); // A : \u0041 is Unicode value for A
}
}