Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to add list inside list without loop.Is is possible or I have to use loop.

Thanks.

What I have tried:

C#
var ItemModel = new ItemModels();
var modelItemList = new List<ItemModels>();
modelItemList = retitem.Select(x =>
{
return new ItemModels()
     {
SKU = x.SKU != null ? x.SKU : "",
SKU2 = x.SKU2 != null ? x.SKU2 : "",
Source = x.Source != null ? x.Source : "",                        
UPC = x.UPC != null ? x.UPC : ""   
      };
}).OrderByDescending(y => y.Barcode).ToList();

ItemModel.ItemList.Add(modelItemList);//it's not right way to add list inside list but i need that without loop.Is it possible?

//Inside Model
public class ItemModels
{
    public ItemModels()
    {
         ItemList = new List<ItemModels>();
    }
    public List<ItemModels> ItemList { get; set; }
}
Posted
Updated 17-Jun-16 0:15am
v2
Comments
phil.o 17-Jun-16 5:42am    
What is wrong with loops?
itsathere 17-Jun-16 6:01am    
loop will take time.Is it possible or not?
phil.o 17-Jun-16 6:13am    
Everything will take time. Momentariness is an illusion.
Usually the loop is not the issue, but what is done in there and how it is done.
Sinisa Hajnal 17-Jun-16 6:43am    
Maybe you could simply assign your list to itemlist? Like this:
ItemModel.ItemList = modelItemList;

1 solution

If you want to add a list to a list use AddRange

C#
ItemModel.ItemList.AddRange(modelItemList);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900