namespace 作业1
{
class Program
{
private static object ToUpper;
static void Main(string[] args)
{
string str = "Hello,Welcome to WuHan,wwwkjdsldjfifnkldsijf!!!!";
Dictionary dic = new Dictionary();
for (int i = 0; i < str.Length; i++)
{
if (char.IsLetter(str[i]))
{
if (dic.ContainsKey(str[i]))
{
dic[str[i]]++;
}
else
{
** str[i]=ToUpper(str[i]);这样为什么不行
if (dic.ContainsKey(str[i]))
{
dic[str[i]]++;
} **
else{
dic.Add(str[i], 1);
}
}
}
}
}
还有
for (int i = 0; i < str.Length; i++)
{
if (char.IsLetter(str[i]))
{
if (dic.ContainsKey( * str[i])=ToUpper(str[i])) *
{
dic[str[i]]++;
}
else
{
dic.Add(str[i], 1);
}
}
插入的key要大写
dic.Add(ToUpper(str[i]), 1);