0

I create a database with the data(id) 8,5,1,9,2,3,4,5. Then i want to retrieve the data and store it in an array. Does anyone can help me? I am using C# and linq to SQL.

My code:

using(DatabaseDataContext db = new DatabaseDataContext())
{
   var query = from p in db.table1
               select p.id;


   int[] myArray = new int[query];
}
1
  • 1
    -1 because you could simply have done a 5 minute search. I believe this question shows a significant lack of research effort. Commented Nov 9, 2012 at 8:07

1 Answer 1

4

Just call an extension method ToArray():

var array = (from p in db.table1
             select p.id).ToArray();
Sign up to request clarification or add additional context in comments.

2 Comments

+1 because you answered faster than me. Perhaps you could mention that specifically the extension method is found in System.Linq.
Wow, just that simple. Thanks!

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.