📒
SDV503
  • SDV503
  • Command Prompt
    • Windows Command Prompt
    • Mac OS Terminal
  • GIT & GITHub
    • GitHub
    • Git
      • Git Workflow
        • Forking Workflow
  • README
    • How to write a readme.md file?
    • Write a better README.me
    • Generate a README for GitHub Repo Quickly
  • Code-comments
    • Clean Comments
    • Writing Comments in a Good way
  • Pair Coding
    • What is Pair Coding?
    • Pair Programming Experience
  • Programming?
    • What is Programming?
    • What Is A Programming Paradigm?
    • JavaScript Programming Paradigms
  • Number Systems
    • Decimal and Binary numbers
  • JavaSCript
    • Introduction To JavaScript
      • The JavaScript Engine
  • JS Call Stack
    • JavaScript call stack
    • JavaScript & Memory
      • Memory Leaks in JavaScript
    • Execution Context and Execution Stack in Javascript
      • Javascript Execution Context and Hoisting
  • JavaScript Variables
    • Introduction to JS Data Types
    • Primitive and Non-Primitive
    • Operator precedence and associativity
      • JS Operators Part One
      • JS Operators Part Two
      • JS Operators Part Three
    • Clean Code for JS Variables
  • JavaScript Scopes
    • Scope (Chain) Visualized
  • Javascript  — this keyword
  • JavaScript Data Types
    • More JavaScript Data Types
  • JavaScript Expressions and Statements
  • if/else, switch and ternary operator
    • If/Else statement
  • Switch Statement
  • Ternary Operator
  • JavaScript Loops
    • Loops in JavaScript
      • Trouble With Loops
  • Objects
    • JavaScript Objects
      • Prototypal Inheritance Visualized
      • JavaScript Number Object
      • JavaScript String Object
  • Functions
    • JavaScript Function Part One
    • JavaScript Function Part Two
    • Immediately Invoked Function Expressions ~ IIFE
    • JS => Arrow Functions
    • JavaScript Callback
    • Hoisting in JavaScript
      • Hoisting Visualized
    • Recursion Functions
    • Curry and Function Composition
  • JavaScript Features
    • JSpread Operator
    • JavaScript Built-in Functions & Objects
  • Data Structures&Algorithms
    • JavaScript’s Data Types
    • Data Structures in JavaScript
      • Introduction to Big O Notation
      • Big O Notation in Javascript
      • Linked Lists
        • Linked Lists — 2
      • Hash Tables
      • Stack & Queue
  • TLDR
    • Single quotes (‘ ’) and double quotes (“ ”) in JavaScript
  • ES6
    • Generators and Iterators
    • Javascript Classes
    • JavaScript closures
    • JavaScript Promises & Async/Await
      • Event Loop Visualized
  • C#
    • What does C#? (C Sharp)
    • C# vs JavaScript
    • What Is The Difference Between C#, .NET, ASP.NET, Microsoft.NET, and Visual Studio?
    • What is the .NET Framework?
    • Methods and Properties of Console Class in C#
    • Datatypes in C#
    • C# Code Comments
    • The if statement
    • The switch statement
    • Loops
    • Comparison operators
    • Addition assignment operators
    • The String Interpolation Operator
    • Arrays
    • Lists
    • Dictionaries
Powered by GitBook
On this page
  • Datatypes:
  • Any Data-
  • Byte:
  • Byte Data Type
  • Char:
  • Char data type
  • String:
  • String Data Type
  • Numeric Data-
  • Numerical datatype without decimal

Was this helpful?

  1. C#

Datatypes in C#

PreviousMethods and Properties of Console Class in C#NextC# Code Comments

Last updated 4 years ago

Was this helpful?

Datatypes:

In programming, data types are declarations for variables. This determines the type and size of data associated with variables. most use datatype is int, string, char.

Any Data-

Byte:

In C#, the byte is used to represent unsigned integers. It is an immutable value type and the range of byte is from 0 to 255(2⁸=256).one byte has 8 bit. In the computer data storage in 0 1 format. This class allows you to create Byte data types and you can perform mathematical and bitwise operations on them like addition, subtraction, multiplication, division, XOR, AND etc.

Image for post

Byte Data Type

Here b variable is assigned decimal equivalent .then it converted into character in “k” because in ASCII table 75 is assign Character “k”.

So, if you want one-byte value then use the byte data type and if you want the maximum value of byte then use byte.MaxValue and for MinValue then use byte.MinValue.

Char:

It is the second data type in C#. its a two-byte length datatype that can contain Unicode data.

Char data type

Here char has two-byte length 2¹⁶=65536.Its uses for only a single Character.

String:

The string data type is an array of characters.string keyword is used for declaring the variable. The string keyword is an alias for the System.String class.

String Data Type

Note: single character use char data type. and for a series of characters then use string. Just read raw data like an image file then use byte data type.

Numeric Data-

Numeric datatype without decimal for signed number has three data types:

Int16, Int32, Int64 are used to represent signed integer with values ranging based on their occupied size in the memory.

Int16: It represents 16-bit (2byte)signed integer and it occupies 16-bit space in memory. Capacity is -32768 to +32767.(2¹⁶=65536/2=32768).

Int16 is nothing but short nshort=123.

Int32: It represents 32-bit (4byte)signed integer and it occupies 32-bit space in memory. Capacity is -2147483648 to +2147483647.(2³²=4294967296/2=2147483647).

Int32 is nothing but int no=123.

Int64: It represents 64-bit (8byte)signed integer and it occupies 64-bit space in memory. Capacity is -9223372036854775808 to +9223372036854775807.(2⁶⁴=18446744073709551616/2=9223372036854775807).

Int64 is nothing but Long no=123.

Numerical datatype without decimal

Numeric datatype without decimal for unsigned number has three data types:

Uint16: It represents 16-bit (2byte)unsigned integer and it occupies 16-bit space in memory. Capacity is 0 to 65536.(²¹⁶=65536).

UInt16 is nothing but ushort nshort=123;

UInt32: It represents 32-bit (4byte)unsigned integer and it occupies 32-bit space in memory. Capacity is 0 to 4294967296.(2³²=4294967296).

UInt32 is nothing but uint no=123;

UInt64: It represents 64-bit (8byte)signed integer and it occupies 64-bit space in memory. Capacity is 0 to 18446744073709551616.(2⁶⁴=18446744073709551616).

UInt64 is nothing but ulong no=123;

Note-depending on what kind of range then choose the data type.

Numeric datatype with a decimal for unsigned number has three data types:

Float: It is a 32-bit single-precision floating-point type. It has 7 digit Precision. To initialize a float variable, use the suffix f or F. Like, float x = 3.23235F; If the suffix F or f will not use then it is treated as double.

Double: It is a 64-bit double-precision floating-point type. It has 16 digit Precision. To initialize a double variable, use the suffix d or D. But it is not mandatory to use suffix because by default floating data types are the double type.

Decimal: The decimal type is a 128-bit data type suitable for financial and monetary calculations. It has 28–29 digit Precision. To initialize a decimal variable, use the suffix m or M. Like as decimal x = 300.5m; If the suffix m or M will not use then it is treated as double.

Note-When you want financial calculation then use decimal data type and when writing some logic for scientific equipment like 100⁰ degree then use double or float or in decimal calculation use float and double.

Other Data-

Bool: a Boolean or bool is a data type that has two possible values: it is either true or false.

DateTime: This DateTime data type represents an instance in time, typically expressed as a date and time of day.

Image for post
Image for post
Image for post
Image for post