程序很简单,如下:
红色部分为错误提示相关的行
using System;
using System.Collections.Generic;
using System.Text;namespace dic1
{
    class Program
    {
        static void Main(string[] args)
{

Dictionary<string,string> myDic = new dictionary<String,String>;

myDic.Add("aaa", "111");
myDic.Add("bbb", "222");
myDic.Add("ccc", "333");
myDic.Add("ddd", "444");
if (!myDic.ContainsKey("ddd"))
{
myDic.Add("ddd", "ddd");
}
else
{
Console.WriteLine("此键已经存在:");
 
} }
    }
}
错误和告警如下
Error 1 A new expression requires () or [] after type D:\myfile\Visual Studio 2005\Projects\dic1\dic1\Program.cs 12 67 dic1
Warning 2 Invalid search path 'C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Lib\' specified in 'LIB environment variable' -- '系统找不到指定的路径。 ' dic1

解决方案 »

  1.   

    Dictionary <string,string> myDic = new dictionary <String,String>(); 
      

  2.   

    Dictionary <string,string> myDic = new dictionary <String,String>(); 
      

  3.   

    Dictionary<string, string> myDic = new Dictionary<String, String>();复制这个替换你的那句
    第一你的dictionary 没有大写
    第2 你的NEW 没写构造函数new Dictionary<String, String>();
      

  4.   

    if (!myDic.ContainsKey("ddd")) 

    //myDic.Add("ddd", "ddd"); //这里已经有一个ddd了不能在增加了,可以修改。myDic["ddd"]= "ddd"; 

    else 

    Console.WriteLine("此键已经存在:"); 
      

      

  5.   

    Dictionary <string, string> myDic = new Dictionary <String, String>(); 
      

  6.   

    Dictionary <string, string> myDic = new Dictionary <String, String>();