Most elegant way to convert string array into a dictionary of strings

后端 未结 8 998
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 18:39

Is there a built-in function for converting a string array into a dictionary of strings or do you need to do a loop here?

8条回答
  •  不思量自难忘°
    2020-12-08 19:12

                Dictionary dictionaryTest = new Dictionary();
    
                for (int i = 0; i < testArray.Length; i++)
                {
                    dictionaryTest.Add(i, testArray[i]);
                }
    
                foreach (KeyValuePair item in dictionaryTest)
                {
    
    
                    Console.WriteLine("Array Position {0} and Position Value {1}",item.Key,item.Value.ToString()); 
                }
    

提交回复
热议问题