首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# 生手来求指导

2013-08-01 
C# 新手来求指导public partial class Form1 : Form{private ArrayList List new ArrayList()public Fo

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);

热点排行