tags:

views:

81

answers:

1

I want to convert a datarow[] into a List<int>

List<int> UserIds;

    public void GetGravatars()
    {
        var cmd = access.GetSqlCommandStoredProcedure("uspMembershipGetUserGravatarList");
        var table = access.ExecuteDataTable(cmd, DAL.Logic.Common.ConnectionStrings.User);

        int[] rows = new int[table.Rows.Count];
        table.Rows.CopyTo(rows, 0);
        UserIds = rows.ToList<int>();

    }

    public bool UserHasGravatar(int userId)
    {
        UserIds.Find(
            delegate(int i)
            {
                return i == userId;
            }
        );
        return false;
    }

What is the best way of doing this?

Edit: My code needs to loop through a list of users, about 40000, and update their image, if they dont have one, so I thought it would be quickest, to load all the userids with images into a List, then check that against all userids in the database, if userid doesnt exists, then update image, otherwise continue.

+8  A: 
rows.Select(r=>/*However you get a single int from a single row*/).ToList();

Update:

I assumed that you are using .NET Framework 3.5? But I may be wrong...

flq
He needs an int[]-Array. So it's ToArray() ;-)
Yves M.
Am I wrong, or should you replace ToList() with ToArray()?
Dave
Oh well, his UserIds type shows List<int>, looks like the specs are contradictin' :)And yes, you can simply use the other extension method, ToArray()
flq
Sorry, I meant I wanted a List<int>
fARcRY