开发者

IEnumerable data type: how to create a null object?

开发者 https://www.devze.com 2023-01-24 06:17 出处:网络
I have an object with several IEnumerable collections: public class Product { public int id {get;set;} public string name {get;set;}

I have an object with several IEnumerable collections:

public class Product
{
    public int id {get;set;}
    public string name {get;set;}
    IEnumerable<CrossSell> CrossSell开发者_JAVA百科s {get;set;}
    IEnumerable<UpSell> UpSells {get;set;}
    IEnumerable<PricePromos> PricePromos {get;set;}
}

I need to create a null object (all properties are blank but not null). Apparently, I cannot just create an Enumerable item.

Other than creating an entirely new class, how could I do this?


Enumerable.Empty<T>() or just a new, zero-length array.


As cdhowie suggests, a zero-element array will work just as well. The syntax is new T[0].

0

精彩评论

暂无评论...
验证码 换一张
取 消