반응형
C# Data Types
In C#, there are two main categories of data types:
value types and reference types.
Value types are simple data types that store their value directly on the stack.
They include:
- Numeric types: int, float, double, decimal, short, long, byte, sbyte, ushort, uint, and ulong.
- Boolean type: bool.
- Character type: char.
- Enumerations: enum.
Reference types are more complex data types that store a reference to the value on the heap.
They include:
- Object type: object.
- String type: string.
- Arrays: int[], string[], etc.
- Class types: custom classes that you define.
Here's an example of declaring and using some C# data types:
1
2
3
4
5
6
7
8
9
|
int age = 30;
double salary = 50000.50;
string name = "John Doe";
bool isEmployed = true;
char gender = 'M';
int[] numbers = { 1, 2, 3, 4, 5 };
object obj = new object();
|
cs |
In this example, we are declaring variables of different data types:
age is an int, salary is a double, name is a string, isEmployed is a bool, and gender is a char. We're also declaring an array of integers, numbers, and an object obj.
반응형
'C# > C# Tutorial' 카테고리의 다른 글
C# Operators | C# Tutorial for Beginners (0) | 2023.02.14 |
---|---|
C# Type Casting | C# Tutorial for Beginners (0) | 2023.02.14 |
C# Constants | C# Tutorial for Beginners (0) | 2023.02.14 |
C# Variables | C# Tutorial for Beginners (0) | 2023.02.14 |
C# Basic Syntax | C# Tutorial for Beginners (0) | 2023.02.14 |