clarification

This is a discussion on clarification within the C# Programming forums, part of the General Programming Boards category; Hello I've just decided to add C# to my repetoire so I'm going through the language at the moment to ...

  1. #1
    WDT
    WDT is offline
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271

    clarification

    Hello

    I've just decided to add C# to my repetoire so I'm going through the language at the moment to iron out the differences between in and c++. At the moment I just need to clarify the value parameter of a method with perhaps an explanation of what's actually happening at the memory level:
    Code:
    IntHolder first = new IntHolder();
    first.i=5;
    IntHolder second = first;
    first.i=6;
    Console.WriteLine (second.i);

    Output
    : 5

    Now normally I would've thought that would produce a 6 since IntHolder second = first is a reference to the same object.
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    IntHolder is a struct, which means value type (no referenses). Had it been a class the output would be 6.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. srand() Clarification
    By Epo in forum C++ Programming
    Replies: 2
    Last Post: 03-03-2005, 11:05 PM
  2. Need a clarification here
    By bithub in forum A Brief History of Cprogramming.com
    Replies: 30
    Last Post: 12-27-2004, 01:06 AM
  3. exercise clarification truth table
    By curlious in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2003, 07:28 PM
  4. A little clarification?
    By Dr Nick in forum C++ Programming
    Replies: 2
    Last Post: 06-20-2002, 02:47 PM
  5. Clarification of Function Templates
    By biosx in forum C++ Programming
    Replies: 2
    Last Post: 02-20-2002, 11:42 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21