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