C#: back2basics Types

C#: back2basics Types




We are going on onto Types in this post so if you’re not sure about whats going on in:

  1. Namespaces
  2. General Class Structure
  3. Method Structure

then please check out those links for an explaination on those.

Pre-Defined Types:

C# has 15 predefined types. Now a type is obviously a structure that houses the value of a variable. Of the 15 predefined types, 13 of these are classified as “simple” types and the remaining two are very creatively named “Not Simple” types. Our 2 non-simple types are the String and Object predefined types.

Simple Types:

Simple types are split into Numeric and Non-Numeric types.

Non-Numeric Types:

  1. bool
  2. char

Numeric Types:

  1. INT
    • byte and sbyte (8bit)
    • short and ushort (16bit)
    • int and uint (32bit)
    • long and ulong(64bit)
  2. Floating Point
    • decimal
    • float
    • double

So these are all the types of pre-defined variables you’ll ever use with .Net (as of .Net3.5 that is) you’ll see with the INT types there is sometimes a “s” or an “u” before the type name. This infers whether it is a “signed” or “unsigned” type. If you curious to know the difference, go have a look at google for the difference between signed and unsigned variables.

User-Defined Types:

We covered the pre-defined types now and those are the types that come with the framework. A lot of people will agree that most .Net applications are just a large grouping of types and custom types that are interacting to perform a specific task. A User-Defined type is a type that you construct. These User-Defined types come in different forms:

  1. Classes
  2. Structs
  3. Arrays
  4. Enums
  5. Delegates
  6. Interface

As we go through this series I will be covering the good ol Classes vs Structs argument soon as well as diving into delegates and interfaces as my knowledge on these are very limited.

The next post in the series will deal with the Stack and Heap and memory allocation for different types.



Leave a Reply