0

I tried the following coding to convert LINQ query to ArrayList, but the error occurs

'Cannot Implicitly convert type System.Collections.Generic.List to System.Collections.ArrayList'

the coding is,

var qry1 = (from a in obj.table1
                       join b in obj.table2
                       on a.id1 equals b.id1                       
                       select new
                       {
                          b.name,
                          b.id
                     });

           ArrayList al = new ArrayList();

           al = qry1.ToList();

how to convert query result to ArrayList.

Thanks in Advance.

2
  • 5
    Do you really need an ArrayList? I'd try to avoid using the non-generic collections if at all possible. Commented May 31, 2012 at 13:29
  • 3
    Forget the ArrayList, in 99.999% you don't need it. Use the strong typed List<T> instead. That's what you already get from ToList. Commented May 31, 2012 at 13:31

1 Answer 1

2
ArrayList al = new ArrayList();

al.AddRange((from a in obj.table1
                       join b in obj.table2
                       on a.id1 equals b.id1                       
                       select new
                       {
                          b.name,
                          b.id
                     }).ToList());

If you really want to use ArrayList.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.