Click here to Skip to main content
14,494,339 members
   

ASP.NET

 
AnswerRe: How do I change this code using Inheritance? Pin
phil.o12-Dec-19 22:23
mvephil.o12-Dec-19 22:23 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede12-Dec-19 22:57
MemberMarc Hede12-Dec-19 22:57 
GeneralRe: How do I change this code using Inheritance? Pin
phil.o12-Dec-19 23:26
mvephil.o12-Dec-19 23:26 
Marc Hede wrote:
"Person does not contain a constructor that takes 0 arguements"
The Person class has a single constructor accepting a string value as argument. Defining a constructor also means that the class does not have any default parameterless constructor. Since the KeyCard class inherits from Person, it has to provide its base class a name argument (so that the base class can be constructed).
There are several solutions to this:

  1. you can define a parameterless constructor in the base class.
  2. you can delete defined constructor in base class (so that compiler generate a default, parameterless one); but this "solution" is not really clever.
  3. you can provide a default name argument in KeyCard's constructor.

In clear:
#region Solution 1 : Defining a parameterless constructor

public class Person
{
   // ...
   public Person() : this("unnamed") { }
}

#endregion

#region Solution 3 : providing a default name in inherited classs' constructor

public class KeyCard : Person
{
   // ...
   public KeyCard(int mykey) : base("unnamed")
   {
      // ...
   }

   // and/or

   public KeyCard(string name) : base(name)
   {
      this.Mykey = -1;
   }

   public KeyCard(string name, int mykey) : base(name)
   {
      this.Mykey = mykey;
   }
}

#endregion


Marc Hede wrote:
"mykey does not exist within current context"
The compiler does not how to differentiate the mykey parameter of the constructor from the protected mykey field. You can either rename one of them, or just define an auto-implemented property and get rid of the protected field:
public int Mykey { get; set; }


Marc Hede wrote:
"method must have a return type"
Probably because you defined the KeyCard class inside the Person class, and then defined a KeyCard constructor inside Person (which is incorrect). Please get the KeyCard class out of the Person (you do not need to nest inheriting classes), and put constructors and methods in the class to which they properly belong.
Good work Smile | :)
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."


modified 13-Dec-19 5:32am.

GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede12-Dec-19 23:49
MemberMarc Hede12-Dec-19 23:49 
GeneralRe: How do I change this code using Inheritance? Pin
F-ES Sitecore12-Dec-19 23:59
mveF-ES Sitecore12-Dec-19 23:59 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede13-Dec-19 0:17
MemberMarc Hede13-Dec-19 0:17 
GeneralRe: How do I change this code using Inheritance? Pin
phil.o13-Dec-19 0:52
mvephil.o13-Dec-19 0:52 
GeneralRe: How do I change this code using Inheritance? Pin
F-ES Sitecore13-Dec-19 0:54
mveF-ES Sitecore13-Dec-19 0:54 
GeneralRe: How do I change this code using Inheritance? Pin
Richard Deeming13-Dec-19 0:58
mveRichard Deeming13-Dec-19 0:58 
GeneralRe: How do I change this code using Inheritance? Pin
Richard MacCutchan13-Dec-19 0:00
mveRichard MacCutchan13-Dec-19 0:00 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede13-Dec-19 0:25
MemberMarc Hede13-Dec-19 0:25 
GeneralRe: How do I change this code using Inheritance? Pin
Richard MacCutchan13-Dec-19 0:44
mveRichard MacCutchan13-Dec-19 0:44 
QuestionHistogram in Asp.net using canvas js Pin
pooja thombare11-Dec-19 20:47
Memberpooja thombare11-Dec-19 20:47 
AnswerRe: Histogram in Asp.net using canvas js Pin
Richard MacCutchan11-Dec-19 21:16
mveRichard MacCutchan11-Dec-19 21:16 
JokeRe: Histogram in Asp.net using canvas js Pin
Richard Deeming12-Dec-19 12:54
mveRichard Deeming12-Dec-19 12:54 
AnswerRe: Histogram in Asp.net using canvas js Pin
phil.o11-Dec-19 23:05
mvephil.o11-Dec-19 23:05 
QuestionI can´t get any output from XML and Binary. Pin
Marc Hede8-Dec-19 3:51
MemberMarc Hede8-Dec-19 3:51 
AnswerRe: I can´t get any output from XML and Binary. Pin
Richard MacCutchan8-Dec-19 5:15
mveRichard MacCutchan8-Dec-19 5:15 
GeneralRe: I can´t get any output from XML and Binary. Pin
Marc Hede8-Dec-19 7:17
MemberMarc Hede8-Dec-19 7:17 
GeneralRe: I can´t get any output from XML and Binary. Pin
Richard MacCutchan8-Dec-19 21:51
mveRichard MacCutchan8-Dec-19 21:51 
QuestionExample Needed Pin
Mycroft Holmes30-Nov-19 12:02
professionalMycroft Holmes30-Nov-19 12:02 
QuestionRe: Example Needed Pin
Maciej Los3-Dec-19 1:53
mveMaciej Los3-Dec-19 1:53 
QuestionProblem with Using Directive Pin
Dawud Ahmad29-Nov-19 17:00
MemberDawud Ahmad29-Nov-19 17:00 
AnswerRe: Problem with Using Directive Pin
phil.o29-Nov-19 22:19
mvephil.o29-Nov-19 22:19 
SuggestionRe: Problem with Using Directive Pin
Richard Deeming3-Dec-19 0:47
mveRichard Deeming3-Dec-19 0:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.