Click here to Skip to main content
15,880,891 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: ASP.Net MVC: How data is serialize into model when pass to client side from action Pin
Mou_kol24-Dec-19 21:14
Mou_kol24-Dec-19 21:14 
GeneralRe: ASP.Net MVC: How data is serialize into model when pass to client side from action Pin
Richard Deeming7-Jan-20 8:09
mveRichard Deeming7-Jan-20 8:09 
QuestionHow do I change this code using Inheritance? Pin
Marc Hede12-Dec-19 21:39
Marc Hede12-Dec-19 21:39 
AnswerRe: How do I change this code using Inheritance? Pin
Richard MacCutchan12-Dec-19 22:15
mveRichard MacCutchan12-Dec-19 22:15 
AnswerRe: How do I change this code using Inheritance? Pin
phil.o12-Dec-19 22:23
professionalphil.o12-Dec-19 22:23 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede12-Dec-19 22:57
Marc Hede12-Dec-19 22:57 
GeneralRe: How do I change this code using Inheritance? Pin
phil.o12-Dec-19 23:26
professionalphil.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:
C#
#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:
C#
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
Marc Hede12-Dec-19 23:49 
GeneralRe: How do I change this code using Inheritance? Pin
F-ES Sitecore12-Dec-19 23:59
professionalF-ES Sitecore12-Dec-19 23:59 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede13-Dec-19 0:17
Marc Hede13-Dec-19 0:17 
GeneralRe: How do I change this code using Inheritance? Pin
phil.o13-Dec-19 0:52
professionalphil.o13-Dec-19 0:52 
GeneralRe: How do I change this code using Inheritance? Pin
F-ES Sitecore13-Dec-19 0:54
professionalF-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
Marc 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
pooja 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
professionalphil.o11-Dec-19 23:05 
QuestionI can´t get any output from XML and Binary. Pin
Marc Hede8-Dec-19 3:51
Marc 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
Marc 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 

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.