Home > Back-end >  error CS1955: Non-invocable member 'Movie.rating' cannot be used like a method
error CS1955: Non-invocable member 'Movie.rating' cannot be used like a method

Time:05-29

After trying multiple languages i settled on C#, and while trying to test my skills, i wanted to output the rating of a new movie object. Sadly, even with me copying word by word the tutorial i fall into the error above...

Movie.cs

namespace Sharpie
{
    public class Movie
    {
        public string title;
        public string director;
        public string rating;

        public Movie(string aTitle, string aDirector, string aRating)
        {
            title = aTitle;
            director = aDirector;
            rating = aRating;
        }
    }
}

Program.cs

namespace Sharpie
{
    class Program 
    {
        static void Main(string[] args)
        {

            Movie avengers = new Movie("Avengers", "Joss Whedon", "PG-13");
            Movie starWars = new Movie("Star Wars", "George Lucas", "PG");
            Movie shrek = new Movie("Shrek", "Adam Adamson", "PG");
            Movie shrek2 = new Movie("Shrek 2", "Adam Adamson", "PG");
        


            Console.WriteLine(avengers.rating());

            Console.ReadLine();
        }
        
        
        }

}

CodePudding user response:

rating is a public member variable but you are using it like a method. Change your line to:

Console.WriteLine(avengers.rating);
  •  Tags:  
  • c#
  • Related