Non-nullable filed '...' must contain a non-null value when exiting constructor

Hi,

I am going through the following tutorial:

https://help.syncfusion.com/wpf/datagrid/getting-started?cs-save-lang=1&cs-lang=csharp

and noticed that the constructor class OrderInfo{... public OrderInfo {...}} in 'Creating Data Model for sample application' produces the following comment:

Constructor Comment.png

Could you please help me what I need to do here?

Thanks.


2 Replies 1 reply marked as answer

MS Madhavan Sathapillai Syncfusion Team June 17, 2024 02:26 PM UTC

Hi kook Jin Noh,

We are able to replicate the reported scenario on our end. To resolve these warnings, use nullable properties. Please check the code snippet below, and we have also attached a simple sample.

Kindly refer the following code snippets.

public class OrderInfo

{

    int? orderID;

    string? customerId;

    public int? OrderID

    {

        get { return orderID; }

        set { orderID = value; }

    }

    public string? CustomerID

    {

        get { return customerId; }

        set { customerId = value; }

    }

}



Regards,
Madhavan S


Attachment: WpfApp1_ffce5a61.zip

Marked as answer

KM Kari Maru June 18, 2025 09:41 AM UTC

If you allow fields to be nullable (e.g., during initialization), use the? However, this is not recommended for Geometry Dash as you need those values ​​to not be null.


Loader.
Up arrow icon