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
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 |
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 |
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 |
What is the difference between webgarden and webfarm?
What is session state in asp net c# with example?
Is comparator a functional interface?
Is c# and c same?
Which class does the remote object has to inherit?
What is the difference between list and arraylist in c#?
What is using keyword?
What?s the C# equivalent of C++ catch (?), which was a catch-all statement for any possible exception?
What are access modifiers used for?
Why do we need escape characters?
How do you convert byte array to hexadecimal string, and vice versa?
what is a callback function?