2

I've been looking around for a while now for some answers, but I cant find it anywhere.

I need a solution for this in C#:

if (stringer[1] == stringer[2]||stringer[3]||stringer[4]||stringer[5])
{

}

this obviously doesn't work in C#, so I need a way to do this.

thank you!

4

3 回答 3

5

Try this:

if (stringer.Skip(1).Any(v => v.Equals(stringer[0])) {
    ...
}

This code compares every item in the stringer array from the second on to the initial item, returning true if the initial item is duplicated anywhere else in the array.

于 2012-08-22T01:36:01.897 回答
1

您必须单独比较每个项目,或使用上述 LINQ 解决方案。

if (stringer[1] == stringer[2] || stringer[1] == stringer[3] || 等等)

于 2012-08-22T01:50:31.673 回答
0

如果有一个字符永远不会出现在字符串中,您可以将其用作分隔符:

 ( "|" + stringer[2] + "|" + stringer[3] + "|" ).IndexOf( "|" + stringer[1] + "|" ) >= 0

丑陋,古老的技术。

于 2012-08-22T02:24:40.007 回答