C# provides a default constructor for me. I write a
constructor that takes a string as a parameter, but want to
keep the no parameter one. How many constructors should I write?

Answers were Sorted based on User's Feedback



C# provides a default constructor for me. I write a constructor that takes a string as a parameter,..

Answer / venu gopal

Two. Once you write at least one constructor, C# cancels the
freebie constructor, and now you have to write one yourself,
even if there?s no implementation in it

Is This Answer Correct ?    6 Yes 1 No

C# provides a default constructor for me. I write a constructor that takes a string as a parameter,..

Answer / tsahi

that depends on weather you are writing a class or a struct.
in a class, the first answer given is correct (i.e. two
constructors). in a struct, you cannot write a default
constructor, and you will always have the automatically
generated one, in addition to any other constructor you may
write by your self.

Is This Answer Correct ?    1 Yes 1 No

C# provides a default constructor for me. I write a constructor that takes a string as a parameter,..

Answer / kiran

namespace SameNamespace
{
class MyBaseClass
{
protected internal int myprotectedinternalint;

private string myName;
public MyBaseClass(string abc)
{
myName = abc;
}
public MyBaseClass()
{

}

}
class MyDerivedClass:MyBaseClass
{
public int GetProtectedInternalMember()
{
return myprotectedinternalint;
}
public MyDerivedClass(int myvalue)
{
myprotectedinternalint = myvalue;
}

}

class MyTest
{
public static void Main()
{
MyBaseClass mbc = new MyBaseClass();
MyDerivedClass mdc = new MyDerivedClass(12);

Console.WriteLine(mdc.GetProtectedInternalMember
());
Console.ReadKey();
}
}
}

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Sharp Interview Questions

What are the 3 different types of arrays?

0 Answers  


What's the difference between class and object?

0 Answers  


How do I do implement a trace?

0 Answers  


What is a byte in c#?

0 Answers  


What is strong name in c# and how can we use it?

0 Answers   DELL,






Name the control which cannot be placed in mdi?

0 Answers  


What are the fundamental differences between value types and reference types?

0 Answers  


Explain manifest in c#.

0 Answers  


Can constructor be private c#?

0 Answers  


Can dictionary have duplicate keys c#?

0 Answers  


Why is it efficient to use System.string under System.Text.StringBuilder ?

0 Answers   Siebel,


What is a nullreferenceexception and how do I fix it?

0 Answers  


Categories