© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
4 replies
TradingRaws4SeoulObjectStoryRaws

❔ Non-nullable field 'rating' must contain a non-null value when exiting constructor

Why am i getting this warning:
Non-nullable field 'rating' must contain a non-null value when exiting constructor
Non-nullable field 'rating' must contain a non-null value when exiting constructor
?
Before exiting the constructor
Rating = aRating
Rating = aRating
is executed and thus rating should be set
rating
rating
to
"G"
"G"
or
"PG"
"PG"
right?

 internal class Book
    {
        private string title;
        private string rating;
        public Book(string aTitle, string aRating)
        {
            title = aTitle;
            Rating = aRating;
        }
        public string Rating
        {
            get { return rating; }
            set { 
                if(value == "G")
                {
                    rating = value;
                }
                else
                {
                    rating = "PG";
                }
            }
        }
    }
 internal class Book
    {
        private string title;
        private string rating;
        public Book(string aTitle, string aRating)
        {
            title = aTitle;
            Rating = aRating;
        }
        public string Rating
        {
            get { return rating; }
            set { 
                if(value == "G")
                {
                    rating = value;
                }
                else
                {
                    rating = "PG";
                }
            }
        }
    }
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Non-nullable property must contain a non-null value when exiting constructor
C#CC# / help
3y ago
✅ Help with non-nullable field must contain a non-null value when exiting constructor.
C#CC# / help
3y ago
❔ Non-nullable property 'Name' must contain a non-null value when exiting constructor
C#CC# / help
3y ago
getting warning: CS8618 - Non-nullable variable must contain a non-null value when exiting construct
C#CC# / help
3y ago