当前位置: 首页>>代码示例>>C#>>正文


C# StringDictionary.Add方法代码示例

本文整理汇总了C#中StringDictionary.Add方法的典型用法代码示例。如果您正苦于以下问题:C# StringDictionary.Add方法的具体用法?C# StringDictionary.Add怎么用?C# StringDictionary.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringDictionary的用法示例。


在下文中一共展示了StringDictionary.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Add

        public void Add()
        {
            int count = 10;
            StringDictionary stringDictionary = new StringDictionary();
            for (int i = 0; i < count; i++)
            {
                string key = "Key_" + i;
                string value = "Value_" + i;

                stringDictionary.Add(key, value);
                Assert.Equal(i + 1, stringDictionary.Count);

                Assert.True(stringDictionary.ContainsKey(key));
                Assert.True(stringDictionary.ContainsValue(value));
                Assert.Equal(value, stringDictionary[key]);
            }

            Assert.False(stringDictionary.ContainsValue(null));

            stringDictionary.Add("nullkey", null);
            Assert.Equal(count + 1, stringDictionary.Count);
            Assert.True(stringDictionary.ContainsKey("nullkey"));
            Assert.True(stringDictionary.ContainsValue(null));
            Assert.Null(stringDictionary["nullkey"]);
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:25,代码来源:StringDictionary.AddTests.cs

示例2: ContainsValue_DuplicateValues

 public void ContainsValue_DuplicateValues(string value)
 {
     StringDictionary stringDictionary = new StringDictionary();
     stringDictionary.Add("key1", value);
     stringDictionary.Add("key2", value);
     Assert.True(stringDictionary.ContainsValue(value));
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:7,代码来源:StringDictionary.ContainsValueTests.cs

示例3: BindCountries

    /// <summary>
    /// Binds the country dropdown list with countries retrieved
    /// from the .NET Framework.
    /// </summary>
    public void BindCountries()
    {
        StringDictionary dic = new StringDictionary();
        List<string> col = new List<string>();

        foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
        {
            RegionInfo ri = new RegionInfo(ci.Name);
            if (!dic.ContainsKey(ri.EnglishName))
                dic.Add(ri.EnglishName, ri.TwoLetterISORegionName.ToLowerInvariant());

            if (!col.Contains(ri.EnglishName))
                col.Add(ri.EnglishName);
        }

        // Add custom cultures
        if (!dic.ContainsValue("bd"))
        {
            dic.Add("Bangladesh", "bd");
            col.Add("Bangladesh");
        }

        col.Sort();

        ddlCountry.Items.Add(new ListItem("[Not specified]", ""));
        foreach (string key in col)
        {
            ddlCountry.Items.Add(new ListItem(key, dic[key]));
        }

        SetDefaultCountry();
    }
开发者ID:rajgit31,项目名称:RajBlog,代码行数:36,代码来源:Profiles.aspx.cs

示例4: Item_Get_DuplicateValues

        public void Item_Get_DuplicateValues()
        {
            StringDictionary stringDictionary = new StringDictionary();
            stringDictionary.Add("key1", "value");
            stringDictionary.Add("key2", "different-value");
            stringDictionary.Add("key3", "value");

            Assert.Equal("value", stringDictionary["key1"]);
            Assert.Equal("different-value", stringDictionary["key2"]);
            Assert.Equal("value", stringDictionary["key3"]);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:11,代码来源:StringDictionary.GetItemTests.cs

示例5: Add_Invalid

        public void Add_Invalid()
        {
            StringDictionary stringDictionary = new StringDictionary();
            stringDictionary.Add("Key", "Value");

            Assert.Throws<ArgumentNullException>("key", () => stringDictionary.Add(null, "value"));

            // Duplicate key
            Assert.Throws<ArgumentException>(null, () => stringDictionary.Add("Key", "value"));
            Assert.Throws<ArgumentException>(null, () => stringDictionary.Add("KEY", "value"));
            Assert.Throws<ArgumentException>(null, () => stringDictionary.Add("key", "value"));
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:12,代码来源:StringDictionary.AddTests.cs

示例6: Remove_DuplicateValues

        public void Remove_DuplicateValues()
        {
            StringDictionary stringDictionary = new StringDictionary();
            stringDictionary.Add("key1", "value");
            stringDictionary.Add("key2", "value");

            stringDictionary.Remove("key1");
            Assert.Equal(1, stringDictionary.Count);
            Assert.False(stringDictionary.ContainsKey("key1"));
            Assert.True(stringDictionary.ContainsValue("value"));

            stringDictionary.Remove("key2");
            Assert.Equal(0, stringDictionary.Count);
            Assert.False(stringDictionary.ContainsKey("key2"));
            Assert.False(stringDictionary.ContainsValue("value"));
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:16,代码来源:StringDictionary.RemoveTests.cs

示例7: ContainsKey_IsCaseInsensitive

 public void ContainsKey_IsCaseInsensitive()
 {
     StringDictionary stringDictionary = new StringDictionary();
     stringDictionary.Add("key", "value");
     Assert.True(stringDictionary.ContainsKey("KEY"));
     Assert.True(stringDictionary.ContainsKey("kEy"));
     Assert.True(stringDictionary.ContainsKey("key"));
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:8,代码来源:StringDictionary.ContainsKeyTests.cs

示例8: Item_Get_IsCaseInsensitive

 public void Item_Get_IsCaseInsensitive()
 {
     StringDictionary stringDictionary = new StringDictionary();
     stringDictionary.Add("key", "value");
     Assert.Equal("value", stringDictionary["KEY"]);
     Assert.Equal("value", stringDictionary["kEy"]);
     Assert.Equal("value", stringDictionary["key"]);
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:8,代码来源:StringDictionary.GetItemTests.cs

示例9: ContainsValue_IsCaseSensitive

 public void ContainsValue_IsCaseSensitive()
 {
     StringDictionary stringDictionary = new StringDictionary();
     stringDictionary.Add("key", "value");
     Assert.False(stringDictionary.ContainsValue("VALUE"));
     Assert.False(stringDictionary.ContainsValue("vaLue"));
     Assert.True(stringDictionary.ContainsValue("value"));
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:8,代码来源:StringDictionary.ContainsValueTests.cs

示例10: Ctor

        public void Ctor()
        {
            StringDictionary stringDictionary = new StringDictionary();
            Assert.Equal(0, stringDictionary.Count);
            Assert.False(stringDictionary.IsSynchronized);
            Assert.Equal(0, stringDictionary.Keys.Count);
            Assert.Equal(0, stringDictionary.Values.Count);

            stringDictionary.Add("key", "value");
            Assert.False(stringDictionary.IsSynchronized);
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:11,代码来源:StringDictionary.CtorTests.cs

示例11: CreateStringDictionary

        public static StringDictionary CreateStringDictionary(int count)
        {
            StringDictionary stringDictionary = new StringDictionary();

            for (int i = 0; i < count; i++)
            {
                stringDictionary.Add("Key_" + i, "Value_" + i);
            }

            return stringDictionary;
        }
开发者ID:MichalStrehovsky,项目名称:corefx,代码行数:11,代码来源:Helpers.cs

示例12: BindGrid

    private void BindGrid()
    {
        StringCollection col = StaticDataService.LoadPingServices();
        StringDictionary dic = new StringDictionary();
        foreach (string services in col)
        {
          dic.Add(services, services);
        }

        grid.DataKeyNames = new string[] { "key" };
        grid.DataSource = dic;
        grid.DataBind();
    }
开发者ID:chandru9279,项目名称:StarBase,代码行数:13,代码来源:PingServices.aspx.cs

示例13: BindCountries

    /// <summary>
    /// Binds the country dropdown list with countries retrieved
    /// from the .NET Framework.
    /// </summary>
    public void BindCountries()
    {
        StringDictionary dic = new StringDictionary();
        List<string> col = new List<string>();

        foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
        {
            RegionInfo ri = new RegionInfo(ci.Name);
            if (!dic.ContainsKey(ri.EnglishName))
                dic.Add(ri.EnglishName, ri.TwoLetterISORegionName.ToLowerInvariant());

            if (!col.Contains(ri.EnglishName))
                col.Add(ri.EnglishName);
        }

        // Add custom cultures
        if (!dic.ContainsValue("bd"))
        {
            dic.Add("Bangladesh", "bd");
            col.Add("Bangladesh");
        }

        col.Sort();

        ddlCountry.Items.Add(new ListItem("[Not specified]", ""));
        foreach (string key in col)
        {
            ddlCountry.Items.Add(new ListItem(key, dic[key]));
        }

        if (ddlCountry.SelectedIndex == 0 && Request.UserLanguages != null && Request.UserLanguages[0].Length == 5)
        {
            ddlCountry.SelectedValue = Request.UserLanguages[0].Substring(3);
            SetFlagImageUrl();
        }
    }
开发者ID:bpanjavan,项目名称:Blog,代码行数:40,代码来源:Profiles.aspx.cs

示例14: runTest

 public virtual bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     IntlStrings intl;
     String strLoc = "Loc_000oo";
     StringDictionary sd; 
     string [] values = 
     {
         "",
         " ",
         "a",
         "aa",
         "tExt",
         "     spAces",
         "1",
         "$%^#",
         "2222222222222222222222222",
         System.DateTime.Today.ToString(),
         Int32.MaxValue.ToString()
     };
     string [] keys = 
     {
         "zero",
         "one",
         " ",
         "",
         "aa",
         "1",
         System.DateTime.Today.ToString(),
         "$%^#",
         Int32.MaxValue.ToString(),
         "     spaces",
         "2222222222222222222222222"
     };
     Array arr;
     ICollection vs;         
     int ind;
     try
     {
         intl = new IntlStrings(); 
         Console.WriteLine("--- create dictionary ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         sd = new StringDictionary();
         Console.WriteLine("1. get Values for empty dictionary");
         iCountTestcases++;
         if (sd.Count > 0)
             sd.Clear();
         if (sd.Values.Count != 0) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001, returned Values.Count = {0}", sd.Values.Count);
         }
         Console.WriteLine("2. get Values on filled dictionary");  
         strLoc = "Loc_002oo"; 
         int len = values.Length;
         iCountTestcases++;
         sd.Clear();
         for (int i = 0; i < len; i++) 
         {
             sd.Add(keys[i], values[i]);
         }
         if (sd.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, count is {0} instead of {1}", sd.Count, len);
         } 
         vs = sd.Values;
         if (vs.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, returned Values.Count = {0}", vs.Count);
         }
         arr = Array.CreateInstance(typeof(string), len);
         vs.CopyTo(arr, 0);
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
             ind = Array.IndexOf(arr, values[i]);
             if (ind < 0) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002b_{0}, Values doesn't contain \"{1}\" value. Search result: {2}", i, keys[i], ind);
             } 
         }
         Console.WriteLine("3. get Values on dictionary with duplicate values ");
         strLoc = "Loc_003oo"; 
         iCountTestcases++;
         sd.Clear();
         string intlStr = intl.GetString(MAX_LEN, true, true, true);
         sd.Add("keykey1", intlStr);        
         for (int i = 0; i < len; i++) 
         {
             sd.Add(keys[i], values[i]);
         }
         sd.Add("keykey2", intlStr);        
         if (sd.Count != len+2) 
         {
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co8767get_values.cs

示例15: GetLanguageDictionary

    public static StringDictionary GetLanguageDictionary(string strFile)
    {
        StringDictionary sdLang = new StringDictionary();

        string fileName = HttpContext.Current.Server.MapPath("~/" + strFile);

        XmlDocument docLang = new XmlDocument();
        using (StreamReader sr = new StreamReader(fileName))
        {
            docLang.Load(sr);
        }

        XmlNodeList nodesWord = docLang.SelectNodes("/language/word");

        if (nodesWord != null)
            foreach (XmlNode word in nodesWord)
                if (word.Attributes != null) sdLang.Add(word.Attributes["Keyword"].Value, word.InnerText);

        return sdLang;
    }
开发者ID:Blogsa,项目名称:blogsa,代码行数:20,代码来源:BSHelper.cs


注:本文中的StringDictionary.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。