C# and it’s data types
Khairul Bashar
Open for Remote & Freelance Opportunities | Back End Engineer | Go, Gin, Vue, Microservices | MSE in Software Engineering
C# (pronounced ‘C sharp’) is a modern, multi-paradigm, object-oriented and type-safe programming language. Since the first introduction in 2000 is it being widely used for developing a variety of applications, including desktop software, web applications, games, and mobile apps. These applications are robust and secure and run in .NET.
The TIOBE index 2023 ranks C# as the 5th most popular language as of today 31st May, 2023. And according to the Stack Overflow survey of 2022, it is the 7th most commonly used language by professional developers.
C# syntax is close to Java and Scala or Kotlin. So one will find it quite easy to work with coming from those backgrounds.?
With that being said, let’s talk about variables and types in C#.
So, what are variables?
The definition of variables stays the same throughout all programming languages. In programming, a variable is like a container that holds a value or a piece of data. It allows you to store and manipulate data during the execution of a program. You can think of variables as named storage locations in the computer's memory. For example, you can have a variable called name to store a person's name or a variable called age to store their age.
Data Types inC#
There are six category of data types in C#. They are as followed:
Numeric Data Types
Numeric data types in C# are used to store numeric values. They can represent integers, floating-point numbers, and decimal numbers. Here's an elaboration of the numeric data types in C#:
Integer Data Types:?
Floating-Point Data Types:
Decimal Data Type:
领英推荐
Textual Data Types
Textual data types in C# are used to store and manipulate sequences of characters or individual characters. Detail on textual data types in C#:
Boolean Data Type
The Boolean data type in C# is used to represent logical values, such as true or false. It is a fundamental data type used for conditions, decision-making, and controlling the flow of programs. The bool data type is used to represent Boolean values. It can only have two possible values: true or false. These values are keywords in C# and are not interchangeable with other numeric values like 0 or 1. Boolean variables are often used in conditional statements and logical operations.
Date and Time Data Types
Date and time data types in C# are used to represent and manipulate dates, times, and duration. They are essential for working with time-related information and performing various operations involving dates and time.
C# also provides additional types and structures related to date and time, including DateTimeOffset (to represent dates and times with time zone information), TimeSpan.Ticks (to access the ticks component of a TimeSpan), and various formatting and parsing options to convert date and time values to and from strings.
Collection Data Types
Collection data types in C# are used to store and manipulate collections or groups of related data elements. They provide different structures and functionalities to organize, access, and modify data efficiently.
Object Data Type
The object data type in C# is the base type for all other types. It is a reference type that can hold values of any other type, including value types and reference types. The object data type is primarily used when you need to work with heterogeneous collections or when the specific type of an object is not known at compile time.
We’ll see more on objects in later discussions.?