© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
6 replies
Yashogi

❔ Object reference set to null

var showTime = ShowTimes.Where(x => x.ShowTimeID == request.ShowTimeId).FirstOrDefault();

    int totalTicketsRequested = request.RequireTickets.Count();

    if (showTime.Theatre.SeatingSize < totalTicketsRequested)
    {
        throw new Exception("There are not enough seats available for this purchase");
    }
var showTime = ShowTimes.Where(x => x.ShowTimeID == request.ShowTimeId).FirstOrDefault();

    int totalTicketsRequested = request.RequireTickets.Count();

    if (showTime.Theatre.SeatingSize < totalTicketsRequested)
    {
        throw new Exception("There are not enough seats available for this purchase");
    }
With the code shown I am trying to grab the showtimeID the user selected and use it to figure out the seating size of the theatre to ensure the total tickets selected by the user don't exceed the seating size
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

NullReferenceException Object reference not set to an instance of an object
C#CC# / help
4y ago
System.NullReferenceException : 'Object reference not set to an instance of an object.'
C#CC# / help
2y ago
✅ System.NullReferenceException: 'Object reference not set to an instance of an object.'
C#CC# / help
2y ago
System.NullReferenceException: Object reference not set to an instance of an object.
C#CC# / help
3y ago