Arrays of References - REFERENCE FUNDAMENTALS - Learn C#

Arrays of References

Learn C#
REFERENCE FUNDAMENTALS

https://www.codecademy.com/courses/learn-c-sharp/lessons/csharp-reference-fundamentals/exercises/arrays-of-references?action=resume_content_item

Step 3 will pass with this code, but throw this error in log.

Program.cs

using System;

namespace LearnReferences
{
  class Program
  {
    static void Main(string[] args)
    {
      Dissertation diss1 = new Dissertation(32, "Anna Knowles-Smith", "Refugees and Theatre");
			Dissertation diss2 = new Dissertation(19, "Lajos Kossuth", "Shiny Happy People");
			Diary dy1 = new Diary(48, "Anne Frank", "The Diary of a Young Girl");
			Diary dy2 = new Diary(23, "Lili Elbe", "Man into Woman");
			//Create a variable books of type Book[] that contains diss1, diss2, dy1, and dy2.
      Book[] books = { diss1, diss2, dy1, dy2 };
      //Make an empty foreach loop that loops through each element in the array.
      foreach (Book f in books)
      {
        //In the body of the loop, print out the Title of each element.
        f.Title();
      }
    }
  }
}

Program.cs(19,11): error CS1955: Non-invocable member ‘Book.Title’ cannot be used like a method. [/home/ccuser/workspace/reference-fundamentals-arrays-of-references/LearnReferences.csproj]

The build failed. Please fix the build errors and run again.

If you add another method to Book, could you use that method the way that you’re using Book.Title?
Is Book.Title a method?
If not, how is it different? What is Book.Title? How is that used?
What does invoke mean?

1 Like

I’m not asking for help. I’m posting a bug. Showing evidence how to bypass the step, either to cheat it, or to think you had the expected answer and not learn the correct answer. That isn’t my solution. This is my solution.

using System;

namespace LearnReferences
{
  class Program
  {
    static void Main(string[] args)
    {
      Dissertation diss1 = new Dissertation(32, "Anna Knowles-Smith", "Refugees and Theatre");
			Dissertation diss2 = new Dissertation(19, "Lajos Kossuth", "Shiny Happy People");
			Diary dy1 = new Diary(48, "Anne Frank", "The Diary of a Young Girl");
			Diary dy2 = new Diary(23, "Lili Elbe", "Man into Woman");
			//Create a variable books of type Book[] that contains diss1, diss2, dy1, and dy2.
      Book[] books = { diss1, diss2, dy1, dy2 };
      //Make an empty foreach loop that loops through each element in the array.
      foreach (Book f in books)
      {
        //In the body of the loop, print out the Title of each element.
        Console.WriteLine(f.Title);
      }
    }
  }
}

By the way, the code above in my first post is from Book.cs, not Program.cs

/me hides

Sorry if that came off mean. Wasn’t my intention.

not at all
but I might need to start being aware of what category a thread is in :stuck_out_tongue:

2 Likes