一个字符串是否在另外一个字符串数组里 Array.Exists 的用法 Array.IndexOf 用法

转:

using System;

class Program
{
    static void Main()
    {
    string[] array = { "cat", "dot", "perls" };

    // Use Array.Exists in different ways.
    bool a = Array.Exists(array, element => element == "perls");
    bool b = Array.Exists(array, element => element == "python");
    bool c = Array.Exists(array, element => element.StartsWith("d"));
    bool d = Array.Exists(array, element => element.StartsWith("x"));

    // Output.
    Console.WriteLine(a);
    Console.WriteLine(b);
    Console.WriteLine(c);
    Console.WriteLine(d);
    }

string[] SetSelectIds = { "aa", "bb", "cc" };

string id =  "bb";

if (Array.Exists(SetSelectIds, element => element.Equals(id))) 

Array.IndexOf(SetSelectIds, id) >= 0; 

posted @ 2015-12-22 16:40  James·wang  阅读(834)  评论(0编辑  收藏  举报