Fremus.co.za

Demistifying Life and Web Development

Doing some C#/CLR stuff

I am busy doing a CBT course with the idea of writing MCTS exams and I started by doing some stuff on C# and the .NET framework that focuses specifically on types. The .NET framework is a strongly typed framework and what we mean by strongly typed is that each variable (or type) that you define or create in you’re code must be assigned to a type. C# in particular is a statically, manifestly and strongly typed language. The .NET framework uses the Common Type System (CTS) which means that the type int in C# and the type Integer in VB.NET refer to the same Int32 type in the CLR. It makes sense therefore that in C# you can define types of int as Int32, which means int is just an alias for Int32. Basic/intrinsic types refer to int’s, bools, long, char, unsigned int, unsigned long, byte, short, sbyte, unsigned short, float and decimal. Its important to understand this because memory in the .NET framework is divided into data structures, named the heap and stack respectively. The basic types are seen as value types that are stored on the stack in a Last In First Out basis. Enumerations, structs and constants are also seen as value types. In contrast user-defined types (objects) are stored on the heap. References to the objects are stored on the stack. If for instance you have an instance of StringBuilder called strb1 and another instance called strb2 and you instantiate strb2 be setting it to strb1 then both instances will point to the same reference on the stack. If you then set the value of strb1 it will have the same value as strb2, and vice verse.

  • Share/Bookmark
posted by fr3dr1k in C# and have No Comments
Tags:

Place your comment

Please fill your data and comment below.
Name
Email
Website
Your comment
Get Adobe Flash playerPlugin by wpburn.com wordpress themes