Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Nullable Class Makes Int Nullable

$
0
0

I have a nullable class property:

public MyDTO? myDTO {get;set;}

Inside MyDTO, I have a int property:

public int RefreshRate {get;set;}

I want to use this property as a parameter to lets say pass into a Timer like so:

    var refreshRate = MyDTO?.RefreshRate;    TruckSearchTimer = new Timer(new TimerCallback(async _ =>    {        if (!cts.IsCancellationRequested)        {            ...        }        await InvokeAsync(StateHasChanged);    }), null, refreshRate, refreshRate);

However, adding the nullable ? turns my int property to a nullable int (int?). My question is, how do I get the int value from my nullable int? I've tried this:

refreshRate.Value;

But .Value isn't found. This is a NET8 Blazor web application.

I'm getting around it by simply checking if the object is null:

if (MyDTO is not null) { ... }

Viewing all articles
Browse latest Browse all 4839

Trending Articles