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?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you declare a variable in c#?

513


Describe the parts of assembly.

522


How to implement delegates in c#.net

545


What are the types of constructors?

501


Is c# scripting language?

502






What is Fragmentation and its Types?

565


How to implement singleton design pattern in c#?

467


List some of the classes used by system.data namespace?

446


Are string objects mutable or immutable?

526


Is typeof c#?

534


Is stringbuilder better than string?

511


Is c# a keyword?

492


What is strong data type in c#?

479


What is an assembly in dotnet?

544


Is dll a library?

485