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


C# StringDictionary.ContainsValue方法代码示例

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


在下文中一共展示了StringDictionary.ContainsValue方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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_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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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"
     };
     int cnt = 0;
     try
     {
         intl = new IntlStrings(); 
         Console.WriteLine("--- create dictionary ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         sd = new StringDictionary();
         Console.WriteLine("1. Remove() from empty dictionary");
         iCountTestcases++;
         if (sd.Count > 0)
             sd.Clear();
         for (int i = 0; i < keys.Length; i++) 
         {
             sd.Remove(keys[0]);
         }
         Console.WriteLine("2. Remove() 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);
         } 
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
             cnt = sd.Count;
             sd.Remove(keys[i]);
             if (sd.Count != cnt - 1) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002b_{0}, didn't remove element with {0} key", i);
             } 
             iCountTestcases++;
             if ( sd.ContainsValue(values[i]) ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002c_{0}, removed wrong value", i);
             } 
             iCountTestcases++;
             if ( sd.ContainsKey(keys[i]) ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002d_{0}, removed wrong value", i);
             } 
         }
         Console.WriteLine("3. Remove() 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);        
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co8761remove_str.cs

示例8: runTest

 public virtual bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     StringDictionary sd; 
     try
     {
         Console.WriteLine("--- default ctor ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         sd = new StringDictionary();
         Console.WriteLine("1. compare to null");
         iCountTestcases++;
         if (sd == null) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001, collection is null after default ctor");
         } 
         Console.WriteLine("2. check Count");
         iCountTestcases++;
         if (sd.Count != 0) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002, Count = {0} after default ctor", sd.Count);
         }
         Console.WriteLine("3. check ContainsValue()");
         iCountTestcases++;
         if (sd.ContainsValue("string")) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003, ContainsValue() returned true after default ctor");
         }
         Console.WriteLine("4. check ContainsKey()");
         iCountTestcases++;
         if (sd.ContainsKey("string")) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0004, ContainsKey() returned true after default ctor");
         }
         Console.WriteLine("5. check ToString()");
         iCountTestcases++;
         string temp = sd.ToString();
         Console.WriteLine(" ToString(): " + temp);
         if (temp.IndexOf("StringDictionary") == -1) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005, ToString() doesn't contain \"StringDictionary\"");
         }
         Console.WriteLine("6. check returned Type");
         iCountTestcases++;
         temp = sd.GetType().ToString().Trim();
         Console.WriteLine(" GetType(): " + temp);
         if (temp.IndexOf("StringDictionary") == -1) 
         {  
             iCountErrors++;
             Console.WriteLine("Err_0006: returned type doesn't contain \"StringDictionary\"");
         }
         Console.WriteLine("7. compare returned Type of two Dictionaries");
         iCountTestcases++;
         string temp1 = (new StringDictionary()).GetType().ToString().Trim();
         if (String.Compare(temp, temp1) != 0) 
         {  
             iCountErrors++;
             Console.WriteLine("Err_0007: returned types of two collections differ");
         }
         Console.WriteLine("8. check IsSynchronized");
         iCountTestcases++;
         Console.WriteLine(" IsSynchronized: " + sd.IsSynchronized);
         if (sd.IsSynchronized) 
         {  
             iCountErrors++;
             Console.WriteLine("Err_0008: IsSynchronized returned {0}", sd.IsSynchronized);
         }
         Console.WriteLine("9. add item and verify");
         iCountTestcases++;
         sd.Add("key", "value");
         iCountTestcases++;
         if (sd.Count != 1) 
         {  
             iCountErrors++;
             Console.WriteLine("Err_0009a: Count returned {0}", sd.Count);
         }
         iCountTestcases++;
         if ( !sd.ContainsKey("key") ) 
         {  
             iCountErrors++;
             Console.WriteLine("Err_0009b: ContainsKey() returned false");
         } 
         iCountTestcases++;
         if ( !sd.ContainsValue("value") ) 
         {  
             iCountErrors++;
             Console.WriteLine("Err_0009c: ContainsValue() returned false");
         }
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co8754ctor.cs

示例9: 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 ind;
     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"
     };
     int cnt = 0;            
     try
     {
         intl = new IntlStrings(); 
         Console.WriteLine("--- create collection ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         sd = new StringDictionary();
         Console.WriteLine("1. Check for empty dictionary");
         for (int i = 0; i < values.Length; i++) 
         {
             iCountTestcases++;
             if (sd.ContainsValue(values[i])) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0001_{0}, returned true for empty dictionary", i);
             }
         } 
         Console.WriteLine("2. add simple strings and verify ContainsValue()");
         strLoc = "Loc_002oo"; 
         iCountTestcases++;
         cnt = values.Length;
         for (int i = 0; i < cnt; i++) 
         {
             sd.Add(keys[i], values[i]);
         }
         if (sd.Count != cnt) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, count is {0} instead of {1}", sd.Count, cnt);
         } 
         for (int i = 0; i < cnt; i++) 
         {
             iCountTestcases++;
             if (!sd.ContainsValue(values[i])) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}b, collection doesn't contain value \"{1}\"", i, values[i]);
             } 
             iCountTestcases++;
             if (!sd.ContainsKey(keys[i])) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}c, collection doesn't contain key \"{1}\"", i, keys[i]);
             } 
         }
         Console.WriteLine("3. add intl strings and verify ContainsValue()");
         strLoc = "Loc_003oo"; 
         int len = values.Length;
         string [] intlValues = new string [len*2];
         for (int i = 0; i < len*2; i++) 
         {
             string val = intl.GetString(MAX_LEN, true, true, true);
             while (Array.IndexOf(intlValues, val) != -1 )
                 val = intl.GetString(MAX_LEN, true, true, true);
             intlValues[i] = val;
         } 
         Boolean caseInsensitive = false;
         for (int i = 0; i < len * 2; i++) 
         {
             if(intlValues[i].Length!=0 && intlValues[i].ToLower()==intlValues[i].ToUpper())
                 caseInsensitive = true;
         }
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co8758containsvalue_str.cs

示例10: GetUniqueName

	public static string GetUniqueName(StringDictionary list, string name)
	{
		// duplicate check
		int counter = 2;
		while(list.ContainsValue(name))
		{
			name = _endNumberRegex.Replace(name, "");
			name += counter.ToString();
			counter++;
		}
		return name;
	}
开发者ID:cnporras,项目名称:wilsonormapper,代码行数:12,代码来源:CommonUtility.cs

示例11: runTest


//.........这里部分代码省略.........
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001d, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("2. GetEnumerator for filled collection");
         strLoc = "Loc_002oo"; 
         iCountTestcases++;
         for (int i = 0; i < values.Length; i++) 
         {
             sd.Add(keys[i], values[i]);
         }
         Console.WriteLine("     - get type");
         iCountTestcases++;
         en = sd.GetEnumerator();
         type = en.GetType().ToString();
         if ( type.IndexOf("Enumerator", 0) == 0 ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, type is not Enumerator");
         }
         Console.WriteLine("     - MoveNext and Current within collection");
         for (int i = 0; i < sd.Count; i++) 
         {
             iCountTestcases++;
             res = en.MoveNext();
             if ( !res ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002b_{0}, MoveNext returned false", i);
             }
             iCountTestcases++;
             curr = (DictionaryEntry)en.Current;
             if (! sd.ContainsValue(curr.Value.ToString()) ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002c_{0}, Current dictionary doesn't contain value from enumerator", i);
             }
             iCountTestcases++;
             if (! sd.ContainsKey(curr.Key.ToString()) ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002d_{0}, Current dictionary doesn't contain key from enumerator", i);
             }
             iCountTestcases++;
             if ( String.Compare(sd[curr.Key.ToString()], curr.Value.ToString(), false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002e_{0}, Value for current Key is different in dictionary", i);
             }
             iCountTestcases++;
             DictionaryEntry curr1 = (DictionaryEntry)en.Current;
             if (! curr.Equals(curr1) ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002f_{0}, second call of Current returned different result", i);
             }
         }
         res = en.MoveNext();
         Console.WriteLine("     - MoveNext outside of the collection");
         iCountTestcases++;
         res = en.MoveNext();
         if ( res ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002g, MoveNext returned true");
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:67,代码来源:co8760getenumerator.cs

示例12: 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"
        };
        int cnt = 0;            
        string ind;            
        try
        {
            intl = new IntlStrings(); 
            Console.WriteLine("--- create collection ---");
            strLoc = "Loc_001oo"; 
            iCountTestcases++;
            sd = new StringDictionary();
            Console.WriteLine("1. add simple strings");
            for (int i = 0; i < values.Length; i++) 
            {
                iCountTestcases++;
                cnt = sd.Count;
                sd.Add(keys[i], values[i]);
                if (sd.Count != cnt+1) 
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0001_{0}a, count is {1} instead of {2}", i, sd.Count, cnt+1);
                } 
                iCountTestcases++;
                if (!sd.ContainsValue(values[i])) 
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0001_{0}b, collection doesn't contain value of new item", i);
                } 
                iCountTestcases++;
                if (!sd.ContainsKey(keys[i])) 
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0001_{0}c, collection doesn't contain key of new item", i);
                } 
                iCountTestcases++;
                if (String.Compare(sd[keys[i]], values[i], false) != 0) 
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0001_{0}d, returned item \"{1}\" instead of \"{2}\"", i, sd[keys[i]], values[i]);
                } 
            }
            Console.WriteLine("2. add intl strings");
            int len = values.Length;
            string [] intlValues = new string [len * 2];
            for (int i = 0; i < len * 2; i++) 
            {
                string val = intl.GetString(MAX_LEN, true, true, true);
                while (Array.IndexOf(intlValues, val) != -1 )
                    val = intl.GetString(MAX_LEN, true, true, true);
                intlValues[i] = val;
            } 
            Boolean caseInsensitive = false;
            for (int i = 0; i < len * 2; i++) 
            {
                if(intlValues[i].Length!=0 && intlValues[i].ToLower()==intlValues[i].ToUpper())
                    caseInsensitive = true;
            }            
            Console.WriteLine(" initial number of items: " + sd.Count);
            strLoc = "Loc_002oo"; 
            for (int i = 0; i < len; i++) 
            {
                iCountTestcases++;
                cnt = sd.Count;
                sd.Add(intlValues[i+len], intlValues[i]);
                if (sd.Count != cnt+1) 
                {
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co8755add_str_str.cs


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