Home » .Net

Data types in C#

Learn: C# programming data types: how many types of data types available in C#? Which are the data types are in Value Types category and which are in Reference 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#, there are two types of data types are used:

  1. Value Types
  2. Reference types
  • A variable of value types directly contains only an object with the value.
  • A variable of reference type directly contains a reference to an object. Another variable may contain a reference to the same object.
  • We can 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.

Here is the list of basic/predefined C# data types with type, size, range etc
Image source: http://apprize.info/c/essential/2.html

C# basic/predefined data types
  • Example of Value Types is: int A = 50; here variable A hold value 50 that can be used in program.
  • We can define new reference types class, interface, and delegate declarations.
    Example of reference type is:
    object ABC = new object();
    ABC.myValue = 50;             
  • Escape Sequences and Verbatim Strings are used in C#
    string X = "\"Hello \nHow are you\"";
    Here \n is used for print new line and \" is used to print double quote on console screen.

Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.