Tuesday, May 5, 2020

C# Tutorial: 02 - C# Data Types & Variables

Tutorial 02: C# Data Types & Variables

Now we have seen basics and syntax of C#, We'll move forward towards variables and data types in C#
Being a strongly type language, you can declare a variable in C# like this:
data_type variable_name;
e.g.
int number;
You can assign value later as per usage of variable as follows:
variable_name = value;
e.g.
number = 20;
or you can declare and initialize in single step like this:
data_type variable_name = value;
e.g.
int number = 20;

Date Types in C#

Following are some data types available in C#
int4 bytes
long8 bytes
float4 bytes
double8 bytes
bool1 bit
char2 bytes
string2 bytes per character
Floating and Integer types are further categorized as follows:

Float Data Type


Integer Data Type

If we dig deeper, data types are categorized in Value types and Reference types. We will explorer what exactly in later lessons. For now just know their classifications are as follows:
Value Types
  • Simple data types
  • Struct
  • Nullable value types
  • Tuple value types
  • Enum type
Reference Types
  • class
  • interface
  • array
  • delegates
 Now create a Console Application in Visual Studio and type code as follow:
In line 19 Console.WriteLine("Integer: "+a); + sign is used for concatenation to string value and Console.ReadKey() is used to still output screen.
Now press F5 from keyboard or use Debug > Start and you will see following output.

In next lesson, we will discuss Operators.

No comments:

Post a Comment