The document discusses variables and data types in C#, noting that variables are used to store data and are declared with a data type, variables can change value during a program's execution, and data types include value types like numbers and reference types like objects and classes. It also covers data type conversion, constants, and syntax rules for declaring variables and constants in C#.
2. Variables
• A variable is used to store data in a program and is declared with an
associated data type
• Variable value can keep changing during the course of a program
• The name of Variable is used to access and read the value stored in it
• Syntax
<datatype> var_name = value;
3. Data Types
• When a variable is declared, a data type is assigned to the variable
• You can store different types of values such as numbers, characters or strings
etc.
• In C# data types are divided into two types
Value Types
Reference Types
5. Reference
• They store the memory reference of other variables
• Reference types are classified as:
Object
String
Class
Delegate
Interface
Array
6. Rules
• A variable name can begin with an uppercase or lowercase letter
• The name can have letters, digits and underscore
• The first character of a variable name should be a letter or underscore
• C# is case sensitive language
• C# keywords can not be used as a variable name
8. Constants
Constants have fixed value that remains unchanged throughout the program
C# allows to declare constants of all value data types
Syntax
const<datatype><identifier> = value;
10. Type Conversion
It allows us to assign value of one data type to another data type
It is possible to convert data types explicitly by using built-in methods,
such as
Convert.ToBoolean,
Convert.ToDouble,
Convert.ToString,
Convert.ToInt32 (int)
and Convert.ToInt64 (long)
Why???
Editor's Notes
Object: Built-in Reference Data type. Base class for all data types
String: Built-in
Class: User defined structure contains methods and properties
Delegates: Reference of methods
Array: Contains collection of values of same data type
Interface: Class Alternate