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()); } }

14th Jul 2022, 7:06 PM
Mustafa Azzoz
Mustafa Azzoz - avatar
8 Respuestas
+ 3
Console.Write("Dog Name is : "); dog.Eat();
14th Jul 2022, 7:19 PM
JaScript
JaScript - avatar
+ 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.
14th Jul 2022, 7:20 PM
Felix Alcor
Felix Alcor - avatar
+ 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.
14th Jul 2022, 7:34 PM
Mustafa Azzoz
Mustafa Azzoz - avatar
+ 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(); }
14th Jul 2022, 7:56 PM
Felix Alcor
Felix Alcor - avatar
+ 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
14th Jul 2022, 8:09 PM
Felix Alcor
Felix Alcor - avatar
0
Felix Alcor Sorry didn't know that , I was using the web app of SoloLearn
14th Jul 2022, 7:36 PM
Mustafa Azzoz
Mustafa Azzoz - avatar
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
14th Jul 2022, 8:01 PM
Mustafa Azzoz
Mustafa Azzoz - avatar
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.
15th Jul 2022, 6:15 AM
JaScript
JaScript - avatar