C# in Simple Terms - Primitive Types, Literals, and Nullables

C# in Simple Terms - Primitive Types, Literals, and Nullables

As we learned in the previous post, C# supports a type system. Part of that system is a group of "basic" types. These types, also called primitive types, form the foundation of many C# programs.

Number Types

The most basic of the primitive types are the number types. These include integral numeric types (which represent whole numbers, like 1, 67, 1957321, 8, and so on) and _floating-point numeric types _(which represent non-whole numbers such as 1.2, 6.99, 8234.66, and so on).


Of the integral numeric types, the type int is the default and most common. int represents a 32-bit integer, with a positive or negative value.

int five = 5;
int thirteenHundred = 1300;
int negativeForty = -40;
int intMaxValue = int.MaxValue; //(2^32 - 1)

The type int is used for many kinds of variables, including math, counters, and iterators.

Short, Long, and Byte

shortlong, and byte are all integral numeric types, like int. However, they represent different ranges of values.

short represents a 16-bit integer:

short three = 3;
short negativeOneHundred = -100;
short shortMaxValue = short.MaxValue; //(2^16 - 1)

long represents a 64-bit integer:

long fifty = 50;
long longMaxValue = long.MaxValue; //(2^64 - 1)

Finally, a byte is a 8-bit integer that only represents positive values.

byte four = 4;
byte byteMaxValue = byte.MaxValue; //(2^8 - 1)

c# c++

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Dicey Issues in C/C++

C/C++ problems. If you are familiar with C/C++then you must have come across some unusual things and if you haven’t, then you are about to. The below codes are checked twice before adding, so feel free to share this article with your friends.

Loops in C++ | For, While, and Do While Loops in C++

In this Video We are going to see how to use Loops in C++. We will see How to use For, While, and Do While Loops in C++.

Using isdigit() in C/C++

In this article, we'll take a look at using the isdigit() function in C/C++. This is a very simple way to check if any value is a digit or not. Let's look

Object Oriented Programming in C++ | C++ OOPs Concepts | Learn Object Oriented C++

C++ is general purpose, compiled, object-oriented programming language and its concepts served as the basis for several other languages such as Java, Python, Ruby, Perl etc.

A Complete Guide to fread() in C/C++

In this article, we’ll take a look at using fread() in C/C++.