C# - Variable types
I will teach you what kind of variables can you use in C#
Data types are used everywhere in a programming language like C#. Because it's a strongly typed language, you are required to inform the compiler about which data types you wish to use every time you declare a variable, as you will see in the chapter about variables. In this chapter we will take a look at some of the most used data types and how they work.
bool is one of the simplest data types. It can contain only 2 values - false or true. The bool type is important to understand when using logical operators like the if statement.
int is short for integer, a data type for storing numbers without decimals. When working with numbers, int is the most commonly used data type. Integers have several data types within C#, depending on the size of the number they are supposed to store.
string is used for storing text, that is, a number of chars. In C#, strings are immutable, which means that strings are never changed after they have been created. When using methods which changes a string, the actual string is not changed - a new string is returned instead.
char is used for storing a single character.
float is one of the data types used to store numbers which may or may not contain decimals.
Reference Type Variables
Reference type variables are made up of two parts: the reference on the stack and the object on the heap. The creation of the object and the reference to the object is commonly known as the instantiation of the object.
Example Reference variable
To declare a reference-type variable, the syntax used are:
string strMimico;city objToronto = null;object objGeneric;
Example Object variable
To create an object on the heap, we go through two steps, as follows:
1. Declare the variable reference.
2. Instantiate the object on the heap by calling the new operator.
City objMimico; //declare objMimico to be a reference to a an
// object of City type
objMimico = new City(); //call the constructor of the City class to return
// a reference that is stored in the objMimico reference
The two lines can be combined into one:
City objMimico = new City();
-
How to Remove Projects from Visual Studio
| By 5min | in General
Visual Studio Remove Projects. How to remove projects from Visual Studio...
-
C# - Hello world explained
| By Victorius | in Programming
I will show you what's the life after Hello Word :)...
-
C# - Variables in higher level
| By Victorius | in Programming
In this article i will teach you how you can use variables in most of your program....
-
C# - The if statement
| By Victorius | in Programming
Now we will learn the most important statement....
-
XA Transaction - Solution for Transaction More Than One Database | By H4d1 | in Programming
Have you ever think that it's too difficult for making database transaction in two different places (or databases) ...
-
Javascript functions for : trim, right trim, left trim, no Apostrophe, is Empty , is Digit , VarChar To Number , is integer , check Is Zero , Get Que | By xxris | in Programming
Javascript functions for : trim, right trim, left trim, no Apostrophe, is Empty , is Digit , VarChar To Number , i...
-
How to access and use a Window's command line | By MaxwellPayne | in Programming
Learn about the Window's command line in DOS and how to use it....
-
How to Learn to Program Your Computer | By dsj8760 | in Programming
This article is about learning to program a computer. It is a general article giving tips on how to learn about pro...
-
Jailbroken iPhones get RickRolled | By explorer | in Programming
First iPhone worm, attacks via SSH and does the classic rick roll gag on the user....
-
C# - Looping in statements | By Victorius | in Programming
We must learn how we can loop in statements. Now here we go....
-
C# - The switch statement | By Victorius | in Programming
Another important statement is the switch statement. Now we will learn it :)...
-
C# - The if statement | By Victorius | in Programming
Now we will learn the most important statement....
-
C# - Variables in higher level | By Victorius | in Programming
In this article i will teach you how you can use variables in most of your program....
-
C# - Hello world explained | By Victorius | in Programming
I will show you what's the life after Hello Word :)...








No comments yet.