簡體   English   中英

Python與C#搜索集合

[英]Python vs C# Searching Collections

是否有一種簡短的方法來查找對象是否在C#的集合中(如運算符中的Python),我認為Linq使您盡可能地接近您?

您可以嘗試使用Linq Any() ,例如

  // Whatever IEnumerable<T> collection
  int[] source = new int[] 
    {1, 2, 3, 4};

  // Put required criterium into Any()
  Boolean has = source.Any(item => item == 3);

  // You can put various criterium into Any(), not necessary ==:
  Boolean hasNegatives = source.Any(item => item < 0);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM