Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何在字典中存储数组值?_Asp.net - Fatal编程技术网

Asp.net 如何在字典中存储数组值?

Asp.net 如何在字典中存储数组值?,asp.net,Asp.net,可以在字典中存储与任何其他类型对象相同的数组: char[] delimiterChars = { ' ', ',', '.', ':', '/', '-', '\t', '=', '&', '?' }; string Str = Convert.ToString(entry.Value); string[] words = Str.Split(delimiterChars); var dict=newdictionary(); dict.Add(1,新int[]{1,2,3});

可以在字典中存储与任何其他类型对象相同的数组:

char[] delimiterChars = { ' ', ',', '.', ':', '/', '-', '\t', '=', '&', '?' };

string Str = Convert.ToString(entry.Value);

string[] words = Str.Split(delimiterChars);
var dict=newdictionary();
dict.Add(1,新int[]{1,2,3});

如果要将数组转换为字典,可以这样做

var dict = new Dictionary<int, int[]>();

dict.Add(1, new int[] { 1, 2, 3});
我的解决方案(在最后几分钟写下):

char[]delimiterChars={'、'、'、'、':'、'/'、'-'、'\t'、'='、'&'、'?'};
字典结果=新字典();
List urlList=新列表();
添加(“测试”);
foreach(url列表中的字符串url)
{
var wordList=url.Split(delimiterChars);
foreach(单词列表中的字符串单词)
{
如果(!result.ContainsKey(word))
{
结果:添加(单词1);
}
其他的
{
结果[字]+;
}
}
}
Console.WriteLine(result.Count);

并经过测试。

解释!仅仅代码是不够的。每个条目的键是什么,值是什么?请解释,为什么你需要在字典中使用这个。我有一些9k的URL,我需要记录最经常出现的单词。我已经能够拆分第一个url的单词,我想将单词存储在字典中,以便当相同的单词在以下url中重复出现时,可以保持每个单词的计数。此外,还可以将生词添加到词典中。谢谢键盘P,将尝试此操作并让您知道结果。不要忘记某些字符的%编码…谢谢,将尝试此操作。
Dictionary<string, int> wordsDict = words.ToDictionary(x => x, x => 1);
Dictionary<string, int> wordsDict = new Dictionary<string,int>();

foreach (string word in words)
{ 
    if(wordsDict.ContainsKey(word)) //if the word already exists
       wordsDict[word]++; //increment the value by 1
    else
       wordsDict.Add(word, 1); //otherwise add the word to the dictionary
}
char[] delimiterChars = { ' ', ',', '.', ':', '/', '-', '\t', '=', '&', '?' };
Dictionary<string, int> result = new Dictionary<string,int>();

List<string> urlList = new List<string>();
urlList.Add("test test test");

foreach (string url in urlList)
{
  var wordList = url.Split(delimiterChars);
  foreach (string word in wordList)
  {
    if (!result.ContainsKey(word))
    {
      result.Add(word, 1);
    }
    else
    {
      result[word]++;
    }
  }
}
Console.WriteLine(result.Count);