Introduction-to-Variables-in-C (3)
Introduction-to-Variables-in-C (3)
Variables in C#
Variables are essential building blocks in C#
programming. They allow you to store and manipulate
data within your code. This presentation will guide you
through the fundamentals of variables in C#, covering
their purpose, declaration, types, and common usage.
by LEUL
What is a Variable?
A variable is a named container used to store data in a computer program.
Think of it as a labeled box where you can put different values, like numbers,
text, or even more complex data. These values can be accessed and changed
throughout your program, enabling flexibility and dynamic behavior.
Named Container
Variables have names, making them easily identifiable and accessible within your code
Data Storage
They act as storage locations for various types of data, such as numbers,
text, or logical values.
Flexibility
The values stored in variables can be modified as needed during program execution.
Declaring and Assigning Variables
In C#, you declare a variable by specifying its data type and name. The data type
determines what kind of data the variable can hold. You then assign an initial value
to the variable using the assignment operator (=).
Data Type
Specify the type of data the variable will hold, e.g., int, string, or bool.
Variable Name
Choose a meaningful name to represent the data the variable will store.
Choose names that clearly Start with lowercase and Avoid using abbreviations or
indicate the purpose of the capitalize the first letter of single-letter variable names.
variable. each subsequent word.
Integer (int) Variables
Integer variables (int) are used to store whole numbers
without any decimal places, both positive and negative.
They are suitable for representing quantities like age,
quantity, or scores. For example, you can store the age of
a person as an integer variable named "userAge".
Calculations
Floating-point variables are essential for calculations involving fractions and decimal values.
Measurements
They are ideal for representing measurements like height, weight, or temperature.
Financial Data
Floating-point variables can accurately store financial values with decimal places.
Boolean (bool) Variables
Boolean variables (bool) are used to store logical values, which can only
be either true or false. They are used for conditions, comparisons, and
decision-making in your code. For example, you can use a bool variable
named "isAdult" to check if a person is an adult.
1 True
Represents a positive or affirmative condition.
2 False
Represents a negative or non-affirmative condition.
3 Conditions
Booleans are used in conditional statements to determine
the flow of execution.