Maha

Maha

  • NA
  • 0
  • 326k

NP1 a.x 20

Jun 4 2007 10:28 AM

June 4, 2007

 

Hi Guys

 

I got the following program from the website. Address is given. I couldn’t understand why output a.x 20. Please anybody explain.

 

Thank you

 

//http://www.java2s.com/Code/CSharp/Language-Basics/Copyastruct.htm

using System;

 

// Define a structure.

struct MyStruct

{

      public int x;

}

 

// Demonstrate structure assignment.

public class StructAssignment

{

      public static void Main()

      {

            MyStruct a;

            MyStruct b;

 

            a.x = 10;

            b.x = 20;

 

            Console.WriteLine("a.x {0}, b.x {1}", a.x, b.x);

 

            a = b;

            b.x = 30;

 

            Console.WriteLine("a.x {0}, b.x {1}", a.x, b.x);

      }

}

/*

a.x 10, b.x 20

a.x 20, b.x 30

*/


Answers (9)