Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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();
        }
        
        
        }

}

>Solution :

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

Console.WriteLine(avengers.rating);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading