Is there a Linq method to add a single item to an IEnumerable?

后端 未结 11 745
感动是毒
感动是毒 2021-02-04 23:10

Basically I am trying to do something like this:

image.Layers

which returns an IEnumerable for all layers except the Parent layer,

11条回答
  •  無奈伤痛
    2021-02-04 23:54

    I once made a nice little function for this:

    public static class CoreUtil
    {    
        public static IEnumerable AsEnumerable(params T[] items)
        {
            return items;
        }
    }
    

    Now this is possible:

    image.Layers.Append(CoreUtil.AsEnumerable(image.ParentLayer, image.AnotherLayer))
    

提交回复
热议问题