Explore 100's Of Free Video Tutorials

Keep Learning, Keep Coding & Keep Sharing

Default Values, Keywords, Identifiers

Notes:

I. Creating different types of variables: [Starts at: 01min:56sec]
II. Default values of different C# data types: [Starts at: 04min:48sec]
III. C# data types type of data: [Starts at: 10min:51sec]
IV. C# keywords: [Starts at: 26min:45sec]
V. C# Identifiers: [Starts at: 29min:03sec]

I. Creating different types of variables: [Starts at: 01min:56sec]
Syntax:
datatype variableName;

Example code:
using UnityEngine;
public class FirstScript : MonoBehaviour {
// Use this for initialization
void Start ()
{
byte b1;
short s1;
int i1;
long l1;

float f1;
double d1;
decimal dcml1;

bool bool1;
char ch1;

string str1;
object obj1;
}
}

II. Default values of different C# data types: [Starts at: 04min:48sec]
Knowing default values of each data type helps in coding better way.
value type (default value):
byte (0)
short (0)
int (0)
long(0)
float (0)
double (0)
decimal (0)

char ( ASCII value 0 or character '\0' )
bool (false)

reference types:
(null)

Note:
all numeric data types default value is 0
bool data type default value is false
char data type default value is ASCII value 0 or character '\0'
string and object default value is null

Example code:
using UnityEngine;
public class FirstScript : MonoBehaviour {
// Use this for initialization
void Start ()
{
byte b1; // 0
short s1; // 0
int i1; // 0
long l1; // 0

float f1; // 0
double d1; // 0
decimal dcml1; //0

bool bool1; // false
char ch1; // '\0'

string str1; // null
object obj1; // null
}
}

III. C# data types type of data: [Starts at: 10min:51sec]
Lets know what type of data each data type can store

Example Code:
using UnityEngine;
public class FirstScript : MonoBehaviour {
// Use this for initialization
void Start ()
{
// integer type ( whole numbers)
byte b1 = 22;
short s1 = 22;
int i1 = 22;
long l1 = 22;

// real type or floating point numbers
float f1=22.22f; // 6 - 7 precisions
double d1=22.22d; // 15 -16 precisions
decimal dcml1=22.22m; // 28 - 29 precisions

// boolean type
bool bool1 = true;

// Character and string type
char c1 ='A';
string str1 = "unity";

// Object type
object obj1 = "unity";
}
}

IV. C# keywords: [Starts at: 26min:45sec]
Keywords are reserved words,
their meaning and purpose is already defined in the compiler
There are more than 87 keywords present in C#

Keywords must be written in lower case
Keywords can not be used as identifier names
i.e.
Name of a variable, constant, function, class, etc.

V. C# Identifiers: [Starts at: 29min:03sec]
Identifiers are sequence of symbols help us to identify specific part of a program
Names given to programmin constructs like
Name of variable, constant, arrays, structures, class, function, etc.

Naming Identifiers:
Identifier names must begin with alphabet
Identifier names must not begin with digit
Accept underscore no other special character allowed, not even space
No successive underscore should be used
They should be meaningful
Keywords should not used
They are case sensitive
They should be unique in the scope

Note:
datatype var = new datatype();
default constructors return default values not the address with respect to value types.