Handle null for class's object

Jassim Al Rahma 1,516 Reputation points


I have the following in my class which gets the data from my database:

public object application { get; set; }

The problem is that sometimes it's null and therefore the app will fail to run.

How can I handle the null here?

I tried:

public object? application { get; set; }

but it's not valid


An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,190 questions
{count} votes

1 answer

Sort by: Most helpful
  1. P a u l 10,401 Reputation points

    Try deserialising as Root rather than List<Root>:

    Root data = JsonSerializer.Deserialize<Root>(result);
    1 person found this answer helpful.