Easy CBASIC Lesson 6 Data Types

of Acoptex.com in Csharp

CBASIC Learning C# basics

Tags: C#, Csharp, C# fundamentals, C# basics

These lessons are designed to keep you engaged with the process of learning C# basics. Our main focus will be on learning C# basics. 

Lesson 6 Data Types

Attachment: ConsoleApp3.zip

The data type tells the C# compiler what kind of value a variable can hold. C# includes many in-built data types for different kinds of data, e.g. String, number, float, decimal, etc.

class Program


        static void Main(string[] args)


            string text = "Hello World!!";

            int num = 100;

            float num1 = 10.2f;

            char letter = 'A';

            bool logic = true;



Each data types includes specific range of values. For example, a variable of int data type can have any value between -2,147,483,648 to 2,147,483,647. The same way, bool data type can have only two value - true or false. The following table lists the data types available in C# along with the range of values possible for each data type:

.NET TypeRange (values)
Byte 0 to 255
SByte -128 to 127
Int32 -2,147,483,648 to 2,147,483,647
UInt32 0 to 4294967295
Int16 -32,768 to 32,767
UInt16 0 to 65,535
Int64 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
UInt64 0 to 18,446,744,073,709,551,615
Single -3.402823e38 to 3.402823e38
Double -1.79769313486232e308 to 1.79769313486232e308
Char Unicode symbols used in text
Boolean True or False
Decimal (+ or -)1.0 x 10e-28 to 7.9 x 10e28
DateTime 0:00:00am 1/1/01 to 11:59:59pm 12/31/9999

As you can see in the above table that each data types (except string and object) includes value range. Compiler will give an error if value goes out of datatype's permitted range. For example, int data type's range is -2,147,483,648 to 2,147,483,647. So if you assign value which is not in this range then compiler would give error.

Alias vs .Net Type

In the above table of data types, first column is for data type alias and second column is actual .Net type name. For example, int is an alias (or short name) for Int32. Int32 is a structure defined in System namespace. The same way, string represent String class.

AliasType Name.Net Type
byte System.Byte struct
sbyte System.SByte struct
int System.Int32 struct
uint System.UInt32 struct
short System.Int16 struct
ushort System.UInt16 struct
long System.Int64 struct
ulong System.UInt64 struct
float System.Single struct
double System.Double struct
char System.Char struct
bool System.Boolean struct
object System.Object Class
string System.String Class
decimal System.Decimal struct
DateTime System.DateTime struct

Data types are further classified as value type or reference type, depending on whether a variable of a particular type stores its own data or a pointer to the data in the memory.

Next -> CBASIC Lesson 7 C# Language version

Other projects of Acoptex.com
Medium Basics: Project 083w Sipeed Maixduino board - Using PlatformIO IDE of Acoptex.com in Sipeed Maixduino 08-08-2019
Medium Basics: Project 083e Sipeed Maixduino board - Uploading MaixPy of Acoptex.com in Sipeed Maixduino 04-08-2019
Medium Basics: Project 083f Sipeed Maixduino board - Using MycroPython of Acoptex.com in Sipeed Maixduino 04-08-2019

Published at 11-11-2018
Viewed: 1039 times