一个数组int A[10],可不可以用for循环,对hashtable循环赋值,
使得key = i,value = A[i].应该怎么写呢?我貌似没找到这样的赋值

解决方案 »

  1.   

     List<int> lt = new List<int>();
                lt.Add(1);
                lt.Add(2);
                lt.Add(3);
                List<int> new_lt = new List<int>();
                for (int i = 0; i < lt.Count; i++)
                {
                    for (int j = 0; j < lt.Count; j++)
                    {
                        if (lt[i] != lt[j] && lt[i] < lt[j])
                        {
                            new_lt.Add(lt[i] + lt[j]);
                        }
                    }
      

  2.   

    hashtable能不能循环赋值呢?
    我需要用到key和value
    拜托了,想想办法吧
      

  3.   

    完全可以实现,在控制台下简单写了个实现代码,以供参考:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] arr=new int[10];
                for(int i=0;i<arr.Length;i++)
                {
                    arr[i]=i*10+i;
                }
                Hashtable hash = new Hashtable();
                for(int i=0;i<arr.Length;i++)
                {
                    hash.Add(i, arr[i]);
                }
                foreach (DictionaryEntry item in hash)
                {
                    Console.WriteLine("Key:"+item.Key+"\t\tValue:"+item.Value);
                }
                Console.ReadKey();
            }
        }
    }