1.1: Data Types

In this module we will study various types in C#.

Definition

Types will be attached to any part of your application that has do with your data and values. Every variable, constant, and expression that gives back a value has a type. Every method has a type for the input value. The .NET Framework class library comes with built in numeric types as well as more complicated types that represent information such as file system, network connections, collections and arrays of objects, and dates.

Basic Types Within C#

Type

Name

Example

Description

Integer

int

20, -1500

A whole number with a size of 32 bits and range from -2,147,483,648 to 2,147,483,647

Float

float

1.5f

32 bit, up to 7 digits

Double

double

1.500000d

64 bit, up to 15-16 digits

Decimal

decimal

8.333333333333333333m

128 bit, up to 28-29 digits, more precise than double or float, but also more costly. Mainly used for financial situations

Boolean

bool

true, false

A true or false statement

String

string

"Hello World"

A collection of characters with a size of up to 2 gigs

Character

char

A

A single character with a size of 16 bits

These are some of the basic types C# uses and examples of when to use the different types. Here is more detail on types in C#.

Practice Question

  • Consider the values below. What is the best type to associate with each one of these items?

    • D

    • 23

    • $3.3333333

    • 15.25

    • -3500

    • Hi!

  • Answers:

    • char

    • int

    • decimal

    • float

    • int

    • string

Next: Data Types Table

Last updated