Problem with Lists

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chamarajanaka
    New Member
    • Jul 2010
    • 9

    Problem with Lists

    I have a List of integers

    Code:
    List<int> LI = new List<int>();
    i wants check whether a particular number exists in the list.if exists do a database updation else do a database insert

    Code:
    foreach (int IT in LI)
                {
               
                }
    can i do this inside the foreach loop or if not possible how to achieve this?????
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    You shouldnt have to loop through the entire list looking for a single value. This would be aweful inefficient. You could use Contains to see if the list contains the value (in this example we'll use 9)

    Code:
    if (list.Contains(9))
    {
        //do your update work here
    }
    Is this what you were looking for?

    Comment

    • chamarajanaka
      New Member
      • Jul 2010
      • 9

      #3
      Originally posted by Richard McCutchen
      You shouldnt have to loop through the entire list looking for a single value. This would be aweful inefficient. You could use Contains to see if the list contains the value (in this example we'll use 9)

      Code:
      if (list.Contains(9))
      {
          //do your update work here
      }
      Is this what you were looking for?
      Exactly!! thanks for the reply. I've got it working

      Comment

      Working...