V.B
V.B

Reputation: 1211

Multiple Lists in One object

I have 3 Lists List<A> ,List<B>,List<C> in C# all the List types are CUSTOM types and NOT same types. I am looking for a type where I could add all the 3 lists and pass on to jQuery and where I could iterate the big object (mix of all three lists).

Any suggestions?

Upvotes: 2

Views: 1185

Answers (3)

apomene
apomene

Reputation: 14389

public class MyList

{
   List <MyList> List { get; set; };

    public   List <MyList> AddList(List<Mylist> List1,List<MyList> List2)
  {
     List1.AddRange(List2).ToList();
     return List1;
  }
}

Upvotes: 0

Christos
Christos

Reputation: 53958

Generally speaking

[WebMethod]
public List<IList> GetList()
{
    List<IList> list = new List<IList>();

    list.Add(list1);
    list.Add(list2);
    list.Add(list3);

    return list;
}

Another approach would be:

[WebMethod]
public List<object> GetList()
{
    List<object> list = new List<object>();

    list.Add(list1);
    list.Add(list2);
    list.Add(list3);

    return list;
}

The method GetList() will reside in your web service class.

Upvotes: 1

Mike Perrenoud
Mike Perrenoud

Reputation: 67928

One approach would be a Tuple:

var tuple = Tuple.Create(listA, listB, listC);

Upvotes: 2

Related Questions