15
Reply

What will be the output of this code?

Priti Kumari

Priti Kumari

Dec 09, 2013
1.9k
0

     struct sample
        {
            public int a;
        }
        class Program
        {
            static void Main(string[] args)
            {
                sample s = new sample();
                s.a = 10;
                Fun(s);
                Console.WriteLine(s.a);
                Console.ReadLine();
            }
            static void Fun(sample ss)
            {
                ss.a = 20;
                Console.WriteLine(ss.a);
            }
        }

    Priti Kumari
    December 09, 2013
    2

    10

    Ramendra kumar verma
    January 23, 2015
    1

    20 10

    Murari Shrivastava
    April 24, 2014
    1

    just 10

    Pramod Lawate
    December 13, 2013
    1

    20 10

    Subash
    July 13, 2016
    0

    20 10

    Ram Nunna
    August 05, 2015
    0

    20 10

    Rahul Prajapat
    June 01, 2015
    0

    20 10

    20 10 coz struct is value type so it will assign different memory for both object.but if you will change struct with class then result will be 20 20 coz class is reference type and it will not assign different memory for different objects of a class.

    Manish Kaushal
    May 23, 2015
    0

    Wht r the correct answer priti ???i think 10 is right ans because in a main method do not create object of fun method

    Rahul Rai
    November 13, 2014
    0

    10

    Rahul Rai
    November 13, 2014
    0

    what is the correct answer ??

    Najna Abdulla
    September 03, 2014
    0

    10 Only

    Tirthak Shah
    January 01, 2014
    0

    20 Next line 10

    Mahesh Alle
    December 16, 2013
    0

    20 10

    Prabakaran Raja
    December 13, 2013
    0