Introduction To Variables in C#
The following article provides an outline for Variables in C#. C# or C Sharp is an all-purpose, object and component-oriented programming language in the series of object-oriented programming languages like C and Java developed by Microsoft. It was developed and created in the early 2000s by Microsoft as a part of the Microsoft .NET Framework initiative. Its design was conceptualized by Anders Hejlsberg. It was designed for the Common Language Infrastructure or CLI program.
It was developed as a multi-faceted and multi-disciplined programming language for the overall .Net Framework and some of its features are:
- Structured and object-oriented.
- Task driven and functional.
- Static and dynamic typing.
- Imperative, functional and partially inferred.
The latest version C# 9.0, released in 2020 in .NET 5.0 Framework.
Table of contents
What Are Variables In C#?
- In C#, variables are storage points of values and data for our programmers who write programs to formulate an assertive composition of programming.
- Variables itself is nothing but a hollow alphabet but it is defined by the types given to it.
- Each variable acts as a storage area for different types of values as and when required in the programs for computation.
- The values stored in the variables define the nature of the variable and its type. Like, whether a variable is numeric in nature or alphabetical and etc.
- The entire programming and coding sequence in C# is filled with several of these variables ultimately leading to the formation of the software’s we see today.
- Most importantly variables are not only used in C# but all other programming languages which includes coding as it is one of the most common and basic but also one of the most crucial and important features of the programming universe.
- Some examples of variables are integer type variable, float type, double, char, string and boolean.
Syntax For Declaring Variables In C#
To declare a variable, first, we need to define the variable, what type of variable it is? As said earlier, each variable is defined by a type as the values or data stored in it are of various natures as and when required during the sequences of programming. Already mentioned in the last point of the previous parameter are the names of the types of variables.
Now the basic sample of syntax for declaring variables in C# is:
type Variable name = value;
- Here, the ‘type’ is the variable type that is int, double or char which defines the variables nature.
- ‘Variable name’ is the name given to a variable like ‘a’, ‘b’ or ‘number’ and the equal sign is used to denote the value for the variable.
Variable Initialization
- Initialization of variables is one of the most basic and rudimentary requirements of any programming language and C# also being a programming language fall under the same category.
- Whenever a variable is required for programming purposes it needs to be initialized methodically.
- Here is where the initialization of a variable takes place by assigning the variable type first followed by the variable name and ending with its value.
- Thus, initialization is a very crucial process in the creation and completion of a program or coding.
- For example, int a = 23; here variable ‘a’ is denoted as an integer type and is initialized to a value of 23.
Different Types Of Variables
There are different types of variables which categorizes each variable separately having separate meanings for each one.
The variable types and its categorization:
Type | Categorization |
INT | Storing integers or numerical values, like 1, 2, 3. |
DOUBLE | Storing decimal values, like 23.22, 5.4. |
CHAR | Stores character type values, like ‘a’ or ‘b’. |
STRING | Stores entire lines of text. |
BOOLEAN | Stores true or false values. |
Examples of Different Types of Variables
Some of the basic examples of different types of variables are given in the below table:
Type | Categorization |
INT | Int num = 20;
‘Int’ is variable type, ‘num’ is the variable name & ‘20’ is the value. |
BOOLEAN
| Bool Boolean = false;
‘Bool’ is variable type, ‘Boolean’ is the variable name & ‘false’ is the value. |
CHAR
| Char word = ‘A’;
‘Char’ is variable type, ‘word’ is the variable name & ‘A’ is the value. |
STRING | String name = “Isaac”;‘String’ is variable type, ‘name’ is the variable name & ‘Isaac’ is the value. |
There are several other types of variables in C# also with its own variable type defining its category and the value assigned to it.
Conclusion
So, C# is a programming language like any other programming languages being a well structured and a popular programming language in computer science universe and it is widely used by a lot of programmers because it is very simple and easy and also it being a part of the .NET Framework of Microsoft thus making it a very commonly used programming language. C# coding is used in several different types of applications like mobile applications, web applications, web servers, games, desktop applications and many more.
Recommended Articles
This is a guide to Variables in C#. Here we discuss the introduction, variable initialization, different types of variables, and examples respectively. You can also go through our other suggested articles to learn more –