TOC

This article is currently in the process of being translated into Vietnamese (~15% done).

The Basics:

Data types

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 là một trong những kiểu dữ liệu đơn giản nhất. Nó chỉ bao gồm 2 giá trị - true (đúng) hoặc false (sai). Là kiểu dữ liệu rất quan trọng để hiểu, khi chính bản thân bool được sử dụng cho các toán tử logic như là câu lệnh if.

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 can contain decimals.

Summary

These are just the most basic data types in C# and I only told you the very basic stuff about them, because it's a pretty dry subject and you may want to see some data types in action before you read more about them. So, move on to the next article, where we'll be using variables to contain data of various types!

Later in this tutorial, we'll go much more in depth with all the various data types found in the .NET framework.


This article has been fully translated into the following languages: Is your preferred language not on the list? Click here to help us translate this article into your language!