C# Programming (CSC 304)
Variables, Data Types
Adedoyin I. OYEBADE
[email protected]
Bowen University,
Iwo, Nigeria
March 11, 2024
OYEBADE A. (BU) CSC 439 March 11, 2024 1 / 11
Presentation Overview
1 C# Variable
Introduction to C# Variable
C# Data Types
OYEBADE A. (BU) CSC 439 March 11, 2024 2 / 11
Introduction C# Variable
1 Variable
• A variable is a name of memory location. It is used to store data.
Its value can be changed and it can be reused many times.
• It is a way to represent memory location through symbol so that
it can be easily identified.
OYEBADE A. (BU) CSC 439 March 11, 2024 3 / 11
C# Variable
1 The basic variable type available in C# can be categorized as:
Figure: C# Variable Types
OYEBADE A. (BU) CSC 439 March 11, 2024 4 / 11
Declaring C# Variables
1 The example of declaring variable is given below:
• int i, j;
• double d;
• float f;
• char ch;
2 We can also provide values while declaring the variables as
given below:
• int i=2,j=4;
• float f=40.2;
• char ch=’B’;
OYEBADE A. (BU) CSC 439 March 11, 2024 5 / 11
Variables Rules
1 Rules for defining Variables
• A variable can have alphabets, digits and underscore
• A variable name can start with alphabet and underscore only. It
can’t start with digit
• No white space is allowed within variable name.
• A variable name must not be any reserved word or keyword e.g.
char, float etc.
2 Valid Variable names:
• int x;
• int x;
• int k20;
3 Invalid variable names:
• int 4;
• int x y;
• int double;
OYEBADE A. (BU) CSC 439 March 11, 2024 6 / 11
C# Data Types
1 Data Types
• Data types are sets (ranges) of values that have similar
characteristics.
• A data type specifies the type of data that a variable can store
such as integer, floating, character etc.
2 Types of Datatype in C# Programming Language
Figure: C# Datatypes Types
OYEBADE A. (BU) CSC 439 March 11, 2024 7 / 11
C# Datatype Types: Value Datatype
1 Value Datatype
• The value data types are integer-based and floating-point
based. C# language supports both signed and unsigned literals.
2 Types of Value Datatype
• Predefined Data Types - such as Integer, Boolean, Float, etc.
• User defined Data Types - such as Structure, Enumerations, etc.
3 The memory size of data types may change according to 32 or
64 bit operating system.
OYEBADE A. (BU) CSC 439 March 11, 2024 8 / 11
C# Datatype Types: Reference Datatype
1 Reference Datatype
• The reference data types do not contain the actual data stored
in a variable, but they contain a reference to the variables.
•
• The reference data types do not contain the actual data stored
in a variable, but they contain a reference to the variables.
2 Types of Reference Datatype
• Predefined Types - such as Objects, String
• User defined Types - such as Classes, Interface
OYEBADE A. (BU) CSC 439 March 11, 2024 9 / 11
C# Datatype Types: Pointer Datatype
1 Pointer Datatype
• The pointer in C# language is a variable, it is also known as
locator or indicator that points to an address of a value.
Figure: C# Pointer Datatypes Types
OYEBADE A. (BU) CSC 439 March 11, 2024 10 / 11
C# Datatype Types: Pointer Datatype
Figure: Symbol used for Pointer
1 Declaring a pointer
• The pointer in C# language can be declared using * (asterisk
symbol)
• int * a; //pointer to int
• char * c; //pointer to char
OYEBADE A. (BU) CSC 439 March 11, 2024 11 / 11