LastIndexOfAny 方法 (Char[], Int32)
 本文章是由機器翻譯。 將指標移到文章內的文字上方即可查看原文。 其他資訊。 譯文 原文

# String.LastIndexOfAny 方法 (Char[], Int32)

.NET Framework 4.6 and 4.5

## 語法

```public int LastIndexOfAny(
char[] anyOf,
int startIndex
)
```

#### 參數

anyOf

Unicode 字元陣列，含有一個或多個要搜尋的字元。
startIndex

## 例外狀況

ArgumentNullException

anyOfnull

ArgumentOutOfRangeException

## 範例

```
// Sample for String.LastIndexOfAny(Char[], Int32)
using System;

class Sample {
public static void Main() {

string br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-";
string br2 = "0123456789012345678901234567890123456789012345678901234567890123456";
string str = "Now is the time for all good men to come to the aid of their party.";
int start;
int at;
string target = "is";
char[] anyOf = target.ToCharArray();

start = (str.Length-1)/2;
Console.WriteLine("The last character occurrence  from position {0} to 0.", start);
Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str);
Console.Write("A character in '{0}' occurs at position: ", target);

at = str.LastIndexOfAny(anyOf, start);
if (at > -1)
Console.Write(at);
else
Console.Write("{0}{0}{0}", Environment.NewLine);
}
}
/*
This example produces the following results:
The last character occurrence  from position 33 to 0.
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
0123456789012345678901234567890123456789012345678901234567890123456
Now is the time for all good men to come to the aid of their party.

A character in 'is' occurs at position: 12

*/

```

## 平台

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (不支援伺服器核心角色), Windows Server 2008 R2 (SP1 (含) 以後版本支援伺服器核心角色，不支援 Itanium)

.NET Framework 並不支援各種平台的所有版本。如需支援版本的清單，請參閱.NET Framework 系統需求