+ -
当前位置:首页 → 问答吧 → vb.net array sort 问题...

vb.net array sort 问题...

时间:2014-04-30

来源:互联网

救教...

dim mycat() as string = {"a","b", "c"}
array.sort(mycat)
listbox1.items.add(mycat)

如果我要出返listbox 中SHOW 返个ARRAY个No. 要点做, 即个result =
0, a
1, b
2, c

谢谢...

作者: will8088   发布时间: 2014-04-30

reply 错 post.........

[ 本帖最后由 a8d7e8 於 2014-3-29 11:32 PM 编辑 ]

作者: a8d7e8   发布时间: 2014-04-30

I'm not sure about vb.net, but in C#, you may put them in following code
复制内容到剪贴板代码: List<String> strings = new List<String> { "b", "c", "a" };
List<String> sortedStrings = new List<String>(strings);
sortedStrings.Sort();

foreach(var each in sortedStrings)
{
Debug.WriteLine("{0} {1}", strings.IndexOf(each), each);
}

/*
2 a
0 b
1 c
*/
If you want only the index without sorting the list, you may use only "sortedStrings.IndexOf(each)"

作者: form5   发布时间: 2014-05-01

唔该晒师兄, 起码我可确定系用indexof, 我GOOGLE一下...

作者: will8088   发布时间: 2014-05-01

如果你要index,就用for唔好用for each,因为indexof,佢要再loop多次黎搵返个index

作者: sinson123   发布时间: 2014-05-01