读书人

C# 生手来求指导

发布时间: 2013-08-01 15:23:18 作者: rapoo

C# 新手来求指导
public partial class Form1 : Form
{
private ArrayList List = new ArrayList();


public Form1()
{
InitializeComponent();

List.Add("1");
List.Add("2");
List.Add("3");
List.Add("4");
List.Add("5");
List.Add("6");
List.Add("7");
List.Add("8");
}

private void button1_Click(object sender, EventArgs e)
{

for (int i = 0; i < List.Count; i++)
{
int value = Convert.ToInt32(List[i]);
if (value % 2 == 0)
{
MessageBox.Show("偶数:" + value );
}
else
{
}
}
}

我想将数组里的字符串 转化成 int形式的数组
然后将这些数字 做一个 从大到小的排序
然后构建一个链表,将当前List内容,复制到新链表之中
我刚接触C#
望高手指教!!!


说的详细点... 能便于理解
跪谢!
[解决办法]
int[] arr = List.OfType<string>().Select(x => int.Parse(x)).ToArray(); // 数组里的字符串 转化成 int形式的数组
arr = arr.OrderBy(x => x).ToArray(); // 将这些数字 做一个 从大到小的排序
LinkedList<int> llist = new LinkedList<int>(); // 构建一个链表
llist.AddRange(arr); // 将当前List内容,复制到新链表之中
[解决办法]
修改成这个
foreach (int item in arr) llist.AddLast(item);

读书人网 >C#

热点推荐