7/21/2010

C# Reference Types



Reference Types:
Reference types are allocated on heap memory 
example: strings, arrays, interfaces, class, delegates events ...

person p1= new person();
person p2=new person(); 
p2=p1;
when we copy one object to another, two copies are stored on stack but both are pointing to the same block of memory on heap.
Reference type contain default value.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ReferenceTypes
{
    class Program
    {
        class value
        {
            public   int x;
        }

        static void Main(string[] args)
        {
            value v = new value();
            Console.WriteLine(v.x);
        }
    }
}

No comments:

Post a Comment