Handle null for class's object

Jassim Al Rahma 1,516 Reputation points
2022-01-16T22:39:03.51+00:00

Hi,

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

Thanks,

C#
C#
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
    2022-01-17T09:37:13.793+00:00

    Try deserialising as Root rather than List<Root>:

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