vb.net:索引号在“for each”

前端之家收集整理的这篇文章主要介绍了vb.net:索引号在“for each”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有时在VB.net我有一些像: @H_404_1@For Each El in Collection Write(El) Next

但是,如果我需要索引号,我必须改变它

@H_404_1@For I = 0 To Collection.Count() - 1 Write(I & " = " & Collection(I)) Next

甚至(更糟)

@H_404_1@I = 0 For Each El In Collection Write(I & " = " & El) I += 1 Next

是否有另一种获取索引的方式?

如果您使用通用集合(Collection(of T)),则可以使用 IndexOf method. @H_404_1@For Each El in Collection Write(Collection.IndexOf(El) & " = " & El) Next

猜你在找的VB相关文章