开发者

IEnumerable data type: how to create a null object?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜