+ 2
How can you change the Speak method to write the sentence "The dog says" + the value of your Sound property.
using System; public class Animal { public string Sound { get; set; } public void Speak() { Console.WriteLine("The dog says woof!"); } } public class Program { public static void Main() { } }
12 Antworten
+ 3
get {return sound; } ! get{return Sound; }
class Animal ! public class Animal
static void main !public static void main
delete the "public class program" above main.
+ 1
Thanks Alvaro! I tried that ,it didn't work.
+ 1
using System;
public class Animal
{
public string Sound { get{return Sound;}
set {Sound="woof!";}
}
public void Speak()
{
Console.WriteLine("The dog says woof!"+this.Sound);
}
}
public class Program
{
public static void Main()
{
}
}
//this is the error I get:
Not all requirements have been met.
Your method body must be 'Console.WriteLine("The dog says " + Sound);'
+ 1
The "this.Sound" looks good.
try doing this as well
{ set = value; } ! set = "woof!"
// in main args add
Animal dog = new Animal;
dog.Sound = "Woof!";
+ 1
Thanks Manuel! . I tried this.
using System;
public class Animal
{
public string Sound { get{return Sound;}
set {Sound=value;}
}
public void Speak()
{
Console.WriteLine("The dog says"+this.Sound);
}
}
public class Program
{
public static void Main()
{
Animal dog = new Animal();
dog.Sound="woof";
}
}
// this is error I get :×
Close
Execution time limit was exceeded
Run-time exception (line -1): Execution time limit was exceeded
Run-time exception (line -1): Execution time limit was exceeded
Run-time exception (line -1): Execution time limit was exceeded
+ 1
I have a similar code that runs
I made two classes and use private, before the get and set.
https://code.sololearn.com/cKz8Zy3CdaCA/?ref=app
0
Maybe this way?
Console.WriteLine("The dog says " + this.Sound);
0
maybe this one
using System;
namespace SoloLearn
{
class Animal {
public string sound;
public string Sound{
get {return sound;}
set {sound = value;}
}
public void Speak(){
Console.WriteLine("The dog says " + sound);
}
}
class Program
{
static void Main(string[] args)
{
Animal a = new Animal ();
a.Sound = "woof";
a.Speak();
}
}
}
0
Did you find the final solution?
0
THIS IS THE ANSWER, IT WORKED FOR ME.
PS: remember to use "Sound" with an uppercase S all through. if not, you won't pass it.
using System;
public class Animal
{
public string Sound
{
get{ return Sound;}
set{ Sound = "woof";}
}
public void Speak()
{
Console.WriteLine("The dog says " + Sound);
}
}
public class Program
{
public static void Main()
{
}
}
0
THIS IS THE ANSWER, IT WORKED FOR ME.
PS: remember to use "Sound" with an uppercase S all through. if not, you won't pass it.
using System;
public class Animal
{
public string Sound
{
get{ return Sound;}
set{ Sound = "woof";}
}
public void Speak()
{
Console.WriteLine("The dog says " + Sound);
}
}
public class Program
{
public static void Main()
{
}
}
0
thank you. working fine