A class has field with value initialized and this field value has also been set into constructor. Which value is set first initialized value or constructor value?

 Posted by SheoNarayan on 9/12/2011 | Category: C# Interview questions | Views: 6787 | Points: 40
Select from following answers:
  1. Constructor value
  2. Initialized value
  3. Both runs at the same time
  4. All Above

Show Correct Answer

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Akiii on: 9/13/2011 | Points: 10
good question...

Thanks and Regards
Posted by: CS1401 on: 9/23/2011 | Points: 10
good question but lack of code beginners cant understand the question fully.. If you attach any example code means it will be better.

Posted by: debal_saha-9451 on: 10/1/2011 | Points: 10
See the Code . Sorry, here i can't able to paste Image , so that you can see the breakpoints. OK, First . Put a break point in constructor: When the debug point is in constructor , the field already assigned with value 99 ,So when the break point come in constructor first , see the field contains value 99 . I explain here with star point
class Program
public static int field1 = 99;

static Program() ******************************* Put break point here( left side) , and run the code,
field1 = 100; ****** When yellow line come here see the value of field 1 , it is 99
}*******************************************************When yellow line comes here , the value will be assigned with 100.

static void Main(string[] args)

So,I hope you can get the answer .
If anything wrong here ,pl correct me .
Posted by: CS1401 on: 10/3/2011 | Points: 10
thanks for your response.
Posted by: Ranjan on: 10/11/2011 | Points: 10

Login to post response