SUNIL GUTTA

SUNIL GUTTA

  • NA
  • 1k
  • 394k

structure vs class initialization via reference diff ?

Mar 26 2013 12:09 PM
Hello friends 

Below mentioned code is working good but doubt is while object reference is created to class object vs structure object .
when calling variable using refernce.variable i am getting 100 in class i.e but in structure i am getting 10 as output ??
 
Is there anything related to value & reference mechanism of structures & class respectively .
 If so can you please do explain me the internal process in depth & i hope this the the major difference when comes to class & structures :)


using System;
namespace codefile1
{
    public class ClassPoint
    {
        public int X;
        public int Y;

        public ClassPoint(int a, int b)       
        {
            X = a;
            Y = b;
        }
        public struct StructPoint
        {
            public int X;
            public int Y;

            public StructPoint(int a, int b)
            {
                X = a;
                Y = b;
            }

            public class Test
            {
              
                static void Main()
                {
                    ClassPoint a = new ClassPoint(10, 10);
                    ClassPoint b = a;
              
                    a.X = 100;

                    StructPoint c = new StructPoint(10, 10);
                    StructPoint d = c;
   
                    c.X = 100;
                    
                    Console.WriteLine( b.X.ToString() + "," + d.X );
                    Console.ReadLine();
                }
            }
        }
    }
}

Out put : 100,10

Ty for help 

Answers (1)