© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
44 replies
Jibz

getting warning: CS8618 - Non-nullable variable must contain a non-null value when exiting construct

I guess, it's not a big deal since the code is getting compiled but I still want to understand why I'm getting this warning and how can I resolve this. I was using a generic struct
truct Rectangle<T> 
{
    T length;
    T width;

    public T Length{
        readonly get{ return length; }
        set{ length = value; }
    }
    public T Width{
        readonly get{ return width; }
        set{ width = value; }
    }

    public Rectangle(T L, T W) // <-- this is where I am getting the warning
    {
        Length = L;
        Width = W;
    }
}
truct Rectangle<T> 
{
    T length;
    T width;

    public T Length{
        readonly get{ return length; }
        set{ length = value; }
    }
    public T Width{
        readonly get{ return width; }
        set{ width = value; }
    }

    public Rectangle(T L, T W) // <-- this is where I am getting the warning
    {
        Length = L;
        Width = W;
    }
}
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
❔ Non-nullable property 'Name' must contain a non-null value when exiting constructor
C#CC# / help
3y ago
❔ Non-nullable field 'rating' must contain a non-null value when exiting constructor
C#CC# / help
4y ago
✅ Help with non-nullable field must contain a non-null value when exiting constructor.
C#CC# / help
3y ago