×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

C# Data Types

In this tutorial, we will learn about the various data types in C# programming language? Last updated : April 04, 2023

What are Data Types?

Data types define what and how data should be stored and used. C# is a type-safe language. Variables are declared as being of a particular type, and each variable is constrained to hold only values of its declared type In C#.

Types of C# Data Types

There are two types of data types are used,

  1. Value Types
    A variable of value types directly contains only an object with the value.
  2. Reference types
    A variable of reference type directly contains a reference to an object. Another variable may contain a reference to the same object.

We can also define our own value types by declaring enumerations or structures.

C# Predefined Data Types

The data types which are predefined in the C# compiler, these are also referred to as Basic Data Type of C#. The value range (minimum and maximum values) and size of these data types are predefined; anyone can not modify the range and size of these data types.

Most Common C# Data Types

The most common data types are:

Data Type Size (in bytes) Description (Range)
int4 bytes-2,147,483,648 to 2,147,483,647
long8 bytes-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float4 bytesUsed to store fractional numbers up to 6-7 decimal digits
double8 bytesUsed to store fractional numbers up to 15 decimal digits
bool1 bittrue or false values
char2 bytesUsed to store a single character
string2 bytes per characterUsed to store a string (sequence of characters)

Here is the list of basic/predefined C# data types with type, size, range etc.

C# basic/predefined data types

Example of Value Types

Example of Value Types is: int A = 50; here variable A hold value 50 that can be used in program.

Example of Reference Types

We can define new reference types class, interface, and delegate declarations.

object ABC = new object();
ABC.myValue = 50;

Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.