vb.net:索引号在“for each”
发布时间:2020-12-17 00:07:03 所属栏目:大数据 来源:网络整理
导读:有时在VB.net我有一些像: For Each El in Collection Write(El)Next 但是,如果我需要索引号,我必须改变它 For I = 0 To Collection.Count() - 1 Write(I " = " Collection(I))Next 甚至(更糟) I = 0For Each El In Collection Write(I " = " El) I += 1Next
有时在VB.net我有一些像:
For Each El in Collection Write(El) Next 但是,如果我需要索引号,我必须改变它 For I = 0 To Collection.Count() - 1 Write(I & " = " & Collection(I)) Next 甚至(更糟) I = 0 For Each El In Collection Write(I & " = " & El) I += 1 Next 是否有另一种获取索引的方式?
如果您使用通用集合(Collection(of T)),则可以使用
IndexOf method.
For Each El in Collection Write(Collection.IndexOf(El) & " = " & El) Next (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |