Initializing object to handle null query results

后端 未结 4 1550
北海茫月
北海茫月 2021-01-15 02:56

I have an object model like this:

public class MyObject{
  public int Prop1{get;set;}
  public int Prop2{get;set;}
}

I use this object in a

4条回答
  •  生来不讨喜
    2021-01-15 03:31

    You could do this way:

    select new MyObject()
                {
                  Prop1 = prop1 ?? 0;
                  Prop2 = prop2 ?? 0;
                };
    

    But it is better to use nullables.

提交回复
热议问题