2

我一直在挣扎。
我该怎么写:

/* initialization */ 
List<Tuple<string, string, string>> mytuples = new List<Tuple<string, string, string>>();

// pseudocode:
if(mytuples.Contains("hello") in Item2)
{
    Console.Write("Success");
}
4

2 回答 2

13
/* initialization */ 

List<Tuple<string, string, string>> mytuples = new List<Tuple<string, string, string>>();


bool containsHello = mytuples.Any(c=>c.Item2.Contains("hello"));

if(containsHello )
{
    Console.Write("Success");
}
于 2012-12-16T12:44:08.767 回答
4

您可以使用 linq 来检查它:

List<Tuple<string, string, string>> mytuples = new List<Tuple<string, string, string>>();

if(mytuples.Where(t=>t.Item2.Contains("hello")).Any())
    Console.Write("Success");      
于 2012-12-16T12:45:54.647 回答