0

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?

3
  • here is my code Commented Oct 19, 2016 at 6:29
  • So, you want to sort items from dearlers.zipcode in the same order as zipcodes right? The question is a little bit unclear Commented Oct 19, 2016 at 6:37
  • Yes it is exactly what I want to do but there query of list<> item to do it. Commented Oct 19, 2016 at 6:49

2 Answers 2

1

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]);
             }
         }
Sign up to request clarification or add additional context in comments.

Comments

0

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

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

1 Comment

I try to do like this string string[] zipcodes = strzipcode.Split(','); List<Dealer> filterList = new List<Dealer>(); for (int x = 0; x < zipcodes.Length-1; x++) { filterList.Add(new Dealer { Zipcode = zipcodes[x] }); } var filteredFileSet = dealers.Where(i => filterList.Contains(i));

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.