Contructor with null value

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 Jahre weitere
Hi!
I have some code like

  Shipment shipment = new Shipment()
                    {
                        OrderId = order.Id,
                        Order = order,
                        TrackingNumber = p.ItemArray[3].ToString(),
                        TotalWeight = Convert.ToDecimal(p.ItemArray[5]),
                        ShippedDateUtc = Convert.ToDateTime(p.ItemArray[4]),
                        CreatedOnUtc = DateTime.Now
                    };

                    _shipmentService.InsertShipment(shipment);


In my case p.ItemArray[4] can be null. So how to avoid exception in this case???
7 Jahre weitere
art_MOO wrote:
Hi!
I have some code like

  Shipment shipment = new Shipment()
                    {
                        OrderId = order.Id,
                        Order = order,
                        TrackingNumber = p.ItemArray[3].ToString(),
                        TotalWeight = Convert.ToDecimal(p.ItemArray[5]),
                        ShippedDateUtc = Convert.ToDateTime(p.ItemArray[4]),
                        CreatedOnUtc = DateTime.Now
                    };

                    _shipmentService.InsertShipment(shipment);


In my case p.ItemArray[4] can be null. So how to avoid exception in this case???


You can check it with conditional operator c#===>https://msdn.microsoft.com/en-us/library/ty67wk28.aspx
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.