在C#或VB.NET中排序数组 [英] Sort array in C# or VB.NET

查看:168
本文介绍了在C#或VB.NET中排序数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


i在数组中有一些数据。

我该如何排序我的阵列?



i猜测是否可以将数据从数组放到数据网格中,然后在datagrid中排序很简单。是对吗?



hi
i have some data in an array.
how must i sort my array?

i guess is it possible to put data from array to a datagrid tthen sort in datagrid is simple. is it right?

for (int j = 0; j < i1; j++)
   {
      dataGridView2[i1, 0].Value = Array_Vazeiat[i1, 0].ToString();
      dataGridView2[i1, 1].Value = Array_Vazeiat[i1, 1].ToString();
      dataGridView2[i1, 2].Value = Array_Vazeiat[i1, 2].ToString();
      dataGridView2[i1, 3].Value = Array_Vazeiat[i1, 3].ToString();

     }





但命令错误:



but there is error in command:

dataGridView2[i1, 0].Value = Array_Vazeiat[i1, 0].ToString()





thanks



我尝试过的事情:



i无法做任何事情。









help



thanks

What I have tried:

i couldn't do any thing.




help

推荐答案

你试过吗:



Array.Sort(myArray);



/ ravi
Have you tried:

Array.Sort(myArray);

/ravi


如何:将数据绑定到Windows窗体DataGridView控件Microsoft Docs [ ^ ]


查看代码:

Look at your code:
for (int j = 0; j < i1; j++)

   {

      dataGridView2[i1, 0].Value = Array_Vazeiat[i1, 0].ToString();

      dataGridView2[i1, 1].Value = Array_Vazeiat[i1, 1].ToString();

      dataGridView2[i1, 2].Value = Array_Vazeiat[i1, 2].ToString();

      dataGridView2[i1, 3].Value = Array_Vazeiat[i1, 3].ToString();



     }

您根本不使用 j ,使用相同的值 - i1 每次循环。因为那可能比数组大 - 因此 j< i1 - 它可能会给你一个索引超出范围的异常。

You don't use j at all, you use the same value - i1 each time round the loop. And since that is probably bigger than the array - hence the j < i1 - it's probably giving you an "index out of range" exception.


这篇关于在C#或VB.NET中排序数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆