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 |
Why do we use public static void main in c#?
What is concrete method in c#?
What is the use of ienumerable?
What is routing in c#?
What is the relation between classes and objects?
If I want to override a method 1 of class A and in class b then how do you declare ?
What debugging tools come with the .NET ssSDK?
what is the index value of the first element in an array?
What is a pre-requisite for connection pooling?
1) how to delete duplicate records from table in sql server 2005 2) what is run time polymorphism
what is the difference between interface and abstraction?
5 Answers Choice Solutions, IBM,
What is the difference between static and constant variables?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)