开发者

get Item Index of arrayList knowing its Name

is there a function that take array list item and bring back item index ?

for开发者_StackOverflow社区 ex:

int indexItem = ArrayList.getItemIndexByName(itemName);


I think that you are looking for IndexOf.

int indexItem = myArray.IndexOf(itemName);

You can use it like this.

String itemName = "Hello";
ArrayList myArray = new ArrayList();
myArray.Add( "Hello" );
myArray.Add( "World" );

// Get index of "Hello"
int indexItem = myArray.IndexOf(itemName);


There is no single method that will give you this, but you could first search for your item by name, then use ArrayList.IndexOf.


Tried storing your items in a Dictionary<string, MyItemType> ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜