C# Exercise - help needed!

Hello Community!
I’m working on the first project in the end of the C# chapter about Interfaces and Inheritance.
This is the first chapter in which no solution code or walk through video is provided.
I went all the way till step 8 and when I tried to run my program I got the error message:

TodoList.cs(27,7): error CS0030: Cannot convert type ‘string’ to ‘int’ [/home/ccuser/workspace/learn-csharp-interfaces-inheritance-app-interfaces/SavingInterface.csproj]

Here’s a link to the exercise - LINK.

I don’t understand where I’m going wrong,

Any help would be greatly appreciated!

Here’s the code in the class where the error is occuring;

using System;

namespace SavingInterface
{
  class TodoList : IDisplayable
  {
    public string[] Todos
    { get; private set; }

    private int nextOpenIndex;

    public TodoList()
    {
      Todos = new string[5];
      nextOpenIndex = 0;
    }

    public void Add(string todo)
    {
      Todos[nextOpenIndex] = todo;
      nextOpenIndex++;
    }

    // defining the Display() method
    public void Display()
    {
      foreach (int nextOpenIndex in Todos)
      {
         Console.WriteLine(Todos[nextOpenIndex]);
      }
    }
  }
}

I hope I provided enough details for you to help me.
Thanks!

Is Todos a string?

foreach (string todo in Todos) {
  Console.WriteLine(todo);
}

Just winging it, mind.

1 Like

Thanks!
That indeed solved it.
Funny thing is that I did go for that as my first option but I think
that accidentally while declaring “todo” in the foreach loop, in
the Console.WriteLine command I entered “todo(s)” without noticing
and was then puzzled by the error message.
:pray: :blush:

1 Like

So…here I am still stuck with the same exercise, just a later stage.
Here’s a screenshot of the error message and the respective class it refers to - Password.cs
I have no idea as to how to proceed.

And here’s another screenshot of the Program.cs

This is the LINK to the specific exercise.

Any help would be greatly appreciated.

What happens if you remove public from that signature?

1 Like

then I get the following error message:

Have to admit not having reached this far yet, barely fledgling in C#. Can you post just the code (raw text, formatted) so we can see the code around line 8?

1 Like

Gladly.

Here’s the full Program.cs code:

using System;

namespace SavingInterface
{
  class Program
  {
    static void Main(string[] args)
    {
      TodoList tdl = new TodoList();
      tdl.Add("Invite friends");
      tdl.Add("Buy decorations");
      tdl.Add("Party");

      tdl.Display();
      tdl.Reset();
      tdl.Display();

      PasswordManager pm = new PasswordManager("iluvpie", true);

      pm.Display();
      pm.Reset();
      pm.Display();
    }
  }
}

And here’s the full Password.cs code:

using System;

namespace SavingInterface
{
  class PasswordManager : IDisplayable, IResetable
  {
    private string Password
    { get; protected set; }

    public bool Hidden
    { get; private set; }

    public PasswordManager(string password, bool hidden)
    {
      Password = password;
      Hidden = hidden;
    }

    // defining a Display() function
    public void Display()
    {
      if (Hidden == false)
      {
        Console.WriteLine(Password);
      }
      else
      {
        Console.WriteLine("*");
      } 
      
      // defining a Reset() method
       void Reset()
      {
        Password = new string[];
        Hidden == false;
      }
    }
  }
}

This is the only exercise so far where no solution or walk through is offered which is a real pity, as these chapters are the most difficult, complex and confusing to understand.