find if an integer exists in a list of integers

后端 未结 8 1333
执笔经年
执笔经年 2020-12-14 05:40

i have this code:

  List apps = getApps();

        List ids;

        List dropdown = apps.ConvertAll(c => new          


        
相关标签:
8条回答
  • 2020-12-14 06:14

    As long as your list is initialized with values and that value actually exists in the list, then Contains should return true.

    I tried the following:

    var list = new List<int> {1,2,3,4,5};
    var intVar = 4;
    var exists = list.Contains(intVar);
    

    And exists is indeed set to true.

    0 讨论(0)
  • 2020-12-14 06:15

    If you just need a true/false result

    bool isInList = intList.IndexOf(intVariable) != -1;
    

    if the intVariable does not exist in the List it will return -1

    0 讨论(0)
提交回复
热议问题