Which Constructor gets fired first Static or Non-Static while creating an object of a class?

 Posted by Kishork80 on 3/19/2011 | Category: .NET Framework Interview questions | Views: 3143 | Points: 40
Answer:

Static constructor will be fired first.
Ex:
class Test{

public Test(){
Console.WriteLine(" public Test()");
}
static Test(){
Console.WriteLine(" static Test()");
}
}
class Program{
static void Main(string[] args){
Test test = new Test();
Console.Read();
}
}


Output:
static Test()
public Test()


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Akiii on: 3/21/2011 | Points: 10
good one sir..

Thanks
Akiii

Login to post response

More Interview Questions by Kishork80