Giang Vivu
Giang Vivu

Reputation: 11

asp.net System.Collections.Generic.List sort in array

I already have a List dealers and strzipcode = Convert.ToString(dr["zero_to_50_miles"]) return a string:

94323,87883,43434,24343 ...

I am trying to sort all of Zip Codes from dearlers that have zipcode in strzipcode (94323,87883,43434,24343) Example My dealer :

"A","94323"

"B","87883"

"C","12345"

"D","12345"

"E","43434"

"F","12345"

"G","12346"

"H","24343"

"I","12347"

So I expect my new dealer will be

"A","94323"

"B","87883"

"E","43434"

"H","24343"

using (var dr = db.ExecuteDataReader("GetZipCodes", CommandType.StoredProcedure, param))
{
    string strzipcode = "";

    while (dr.Read())
    {
        strzipcode = Convert.ToString(dr["zero_to_50_miles"]);
    }
    string[] zipcodes = strzipcode.Split(',');
    for (int a = 0; a < zipcodes.Length - 1; a++)
    {
        var cartr = (from i in dealers where i.Zipcode == strzipcode select i).ToList();
        dealers.Find(cartr);
    }
    var cartr = (from i in dealers where i.Zipcode == strzipcode select i).ToList();
}

What shoud I do?

Upvotes: 0

Views: 61

Answers (2)

Coke
Coke

Reputation: 985

Iterate through dealer and find mismatches with strzip, then remove redundant items:

   for (int i = 0; i < dealer.Count; i++) {
             if (!strzipcode.Contains(dealer[i]))
             {
                 dealer.Remove(dealer[i]);
             }
         }

Upvotes: 1

Santosh Shirkar
Santosh Shirkar

Reputation: 319

You can use linq for filter specific number value. For Ex.

var filteredFileSet = fileList.Where(item => filterList.Contains(item));

Upvotes: 0

Related Questions