0
How to concatenate string and void in C# ? The main problem is in the last line of code .
namespace Csharp_Assignment_5 { public abstract class Animal { public string Name { get; set; } public abstract void Eat(); } } namespace Csharp_Assignment_5 { public class Dog : Animal { public override void Eat() { Console.WriteLine("The Dog is eating"); } } } namespace Csharp_Assignment_5.Controllers { public class HomeController : Controller { public ActionResult Index() { Dog dog = new Dog(); dog.Name = "Patcho"; return Content("Dog Name is : " & dog.Eat()); } }
8 ответов
+ 3
Console.Write("Dog Name is : ");
dog.Eat();
+ 1
Your Methode named Eat() does not have any value and can it be that you want as Output. "Dog Name is: Patcho"?
Then you need to write return Content("Dog Name is: " + dog.Name);
For further help should you send the entire Code, and pls do so with writing your code in "Code" and Sharing the Link to us.
+ 1
Felix Alcor JaScript
C# Assignment 5 :
Create a C# program that implements an abstract class Animal that has a Name property of type text and three methods SetName (string name), GetName, and Eats. The Eat method will be an abstract method of type void.
You will also need to create a Dog class that implements the above Animal class and the Eat method that says the dog is Eating.
To test the program ask the user for a dog name and create a new Dog type object from the Home controller Index Action of the application, give the Dog object a name, and then execute the GetName and Eat methods.
+ 1
Mustafa Azzoz Don't worry you made it so we understand.
I would recommend you First making the other Methodes too, also SetName(string name) and GetName(). Later should the Part Look Like:
public ActionResult Index()
{
Dog dog = new Dog();
dog.SetName("Patcho");
dog.Eat();
dog.GetName();
}
+ 1
I would most likely try something like
public abstract void GetName(string name)
{
this.Name = name;
}
And then dog.GetName(Console.ReadLine());
But I'm unsure because I never worked with ASP.netmvc
0
Felix Alcor Sorry didn't know that , I was using the web app of SoloLearn
0
Felix Alcor How the instructor mentioned that the user should input the dog name ?
, I tried to use
dog.Name = Console.ReadLine() but the IIS Express was loading infinitely
0
Mustafa Azzoz why do you work with IIS Express, is that why don‘t see the void main part of your program?
I would not recommend it in the learning phase of programming.