Please help me with the task: Everyone likes messages nowadays

Hello, I’m working on this task:

Remove implementation and all forbidden members from the interface IMessage. Move them to the class Message, so that class Message implements interface IMessage. Your program should compile.

Here is my code:


namespace Interfaces
{
   public interface IMessage
   {
       string Payload { get; }

       string Type { get; }

       void Read(string payload);
   }

   public class Message : IMessage
   {
       public string Type
       {
           get
           {
               return "Encrypted message";
           }
       }

       public string Payload
       {
           get
           {
               return Payload;
           }
           set
           {
               Payload = value;
           }
       }

       public void Read(string payload)
       {
           Payload = payload;
       }
   }

   public class EveryoneLikesSendingMessagesNowadays
   {
       public static void Main()
       {
           var message = new Message();

           message.Read("I will never implement methods and properties in an interface.");

           Console.WriteLine(message.Payload);
       }
   }
}

Can anyone please help me to solve it?

you’ve completely removed:

private string _payload;

Move it to class Message and use for your variables :slight_smile:

1 Like

Thanks a lot. I remembered that not-implemented properties need to add fild. It`s work)

1 Like