About
In this code snippet, we will take a look at data types in C#.
Data types are used to define the type of data a variable can hold(other members have data types too but it’s not important for now). For example, to store whole numbers you can use int, string for text, char for a single character, double for numeric values with decimal points … Data types also differ in size, byte can hold values from 0 to 255, short can hold values from -32,768 to 32,767, int can hold values from -2,147,483,648 to 2,147,483,647, …
Also, there are two kinds of data types, reference and value types. Reference types(object, class, interface, delegate, record) only contain a reference(or referred to as pointers in other languages) to the actual value/object meanwhile value types(int, char, float, …) contain the actual value in the memory location referenced by the variable name.
This was just a quick overview of data types. You can find out more here.
Let’s look at the code example below to see how to use data types.
Code:
[amp-gist id=”344aa9ef4cc170ad253b8ebfc0f41018″]