"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

September 09, 2012

C# Fundamentals


This time is all about fundamentals of C# . Going beyond theoretical basics.

Tip #1 - Why Value Types are stored in Stack and not in Heap
This blog post (The Truth About Value Types) was the answer. It is a recommendation that CLR does on your behalf to store value types in stack. Short Lived storage (value types) live in stack. Long duration (reference types) live in heap

Tip #2 - Garbage Collection process, Phases Involved
Mark, Sweep and Compact. More details refer The Stack Is An Implementation Detail, Part Two

Tip #3 - Abstract Class VS Interfaces
  • Interface - Can define methods but not implement them
  • Abstarct Class - Can define/implement methods/members but cannot instantiate abstract classes
using System;
namespace examplecode
{
    abstract class AClass
    {
        int aMember;
        public void printVal()
        {
            Console.WriteLine("Example AbstractClass");
        }
    }
    interface iTest
    {
        void printValInterface();
    }
    class Program:AClass,iTest
    {
        public void printValInterface()
        {
            Console.WriteLine("Example printValInterface");
        }
        public static void Main()
        {
            Program RunProgram = new Program();
            RunProgram.printVal();
            RunProgram.printValInterface();
            Console.ReadLine();
        }
    }
}
 
Tip #4 - Why multiple inheritance is not supported in .NET
Answer from stackoverflow question (Why is Multiple Inheritance not allowed in Java or C#?) is realistic and impressive. The benefits are too less and adds a lot of complexity to support multiple inheritance.
 
Tip #5 - Disassembly Good Example
 
Couple of MSDN blog posts were very very impressive. A must read for every developer
 
Happy Learning!!!

No comments: