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


C# ListDictionary.Contains方法代码示例

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


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

示例1: Constructor_DefaultTests

 public static void Constructor_DefaultTests(ListDictionary ld)
 {
     Assert.Equal(0, ld.Count);
     Assert.False(ld.IsReadOnly);
     Assert.Empty(ld);
     Assert.Empty(ld.Keys);
     Assert.Empty(ld.Values);
     Assert.False(ld.Contains(new object()));
     Assert.Null(ld[new object()]);
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:10,代码来源:ListDictionaryTests.cs

示例2: AddTest

 public static void AddTest(bool addViaSet)
 {
     ListDictionary added = new ListDictionary();
     IList keys = new ArrayList();
     IList values = new ArrayList();
     for (int i = 0; i < s_dictionaryData.Length; i++)
     {
         string key = s_dictionaryData[i].Key;
         string value = s_dictionaryData[i].Value;
         Assert.Equal(i, added.Count);
         Assert.Null(added[key]);
         Assert.False(added.Contains(key));
         added.Add(addViaSet, key, value);
         keys.Add(key);
         values.Add(value);
         Assert.Equal(value, added[key]);
         Assert.True(added.Contains(key));
         Assert.Equal(i + 1, added.Count);
         CollectionAsserts.Equal(keys, added.Keys);
         CollectionAsserts.Equal(values, added.Values);
         Assert.Throws<ArgumentException>(() => added.Add(key, value));
         added[key] = value;
     }
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:24,代码来源:ListDictionaryTests.cs

示例3: RemoveTest

 public static void RemoveTest(ListDictionary ld, KeyValuePair<string, string>[] data)
 {
     Assert.All(data, element =>
     {
         Assert.True(ld.Contains(element.Key));
         ld.Remove(element.Key);
         Assert.False(ld.Contains(element.Key));
     });
     Assert.Equal(0, ld.Count);
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:10,代码来源:ListDictionaryTests.cs

示例4: Contains_NullTest

 public static void Contains_NullTest(ListDictionary ld, KeyValuePair<string, string>[] data)
 {
     Assert.Throws<ArgumentNullException>("key", () => ld.Contains(null));
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:4,代码来源:ListDictionaryTests.cs

示例5: Add_MultipleTypesTest

        public static void Add_MultipleTypesTest(bool addViaSet)
        {
            ListDictionary added = new ListDictionary();
            added.Add(addViaSet, "key", "value");
            added.Add(addViaSet, "key".GetHashCode(), "hashcode".GetHashCode());

            Assert.True(added.Contains("key"));
            Assert.True(added.Contains("key".GetHashCode()));
            Assert.Equal("value", added["key"]);
            Assert.Equal("hashcode".GetHashCode(), added["key".GetHashCode()]);
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:11,代码来源:ListDictionaryTests.cs

示例6: Add_CustomComparerTest

        public static void Add_CustomComparerTest(bool addViaSet)
        {
            ObservableStringComparer comparer = new ObservableStringComparer();
            ListDictionary added = new ListDictionary(comparer);

            for (int i = 0; i < s_dictionaryData.Length; i++)
            {
                string key = s_dictionaryData[i].Key;
                string value = s_dictionaryData[i].Value;

                Assert.Equal(i, added.Count);
                comparer.AssertCompared(i, () => Assert.Null(added[key]));
                comparer.AssertCompared(i, () => Assert.False(added.Contains(key)));

                // comparer is called for each element in sequence during add.
                comparer.AssertCompared(i, () => added.Add(addViaSet, key, value));
                comparer.AssertCompared(i + 1, () => Assert.Equal(value, added[key]));
                comparer.AssertCompared(i + 1, () => Assert.True(added.Contains(key)));
                Assert.Equal(i + 1, added.Count);
                comparer.AssertCompared(i + 1, () => Assert.Throws<ArgumentException>(() => added.Add(key, "duplicate")));
            }
            Assert.Equal(s_dictionaryData.Length, added.Count);

            // Because the dictionary maintains insertion order, "add"-ing an already-present element only iterates
            // until the initial key is reached.
            int middleIndex = s_dictionaryData.Length / 2;
            string middleKey = s_dictionaryData[middleIndex].Key;
            string middleValue = s_dictionaryData[middleIndex].Value;

            Assert.Equal(middleValue, added[middleKey]);
            Assert.True(added.Contains(middleKey));
            // Index is 0-based, count is 1-based
            //  ... Add throws exception
            comparer.AssertCompared(middleIndex + 1, () => Assert.Throws<ArgumentException>(() => added.Add(middleKey, "middleValue")));
            Assert.Equal(middleValue, added[middleKey]);
            Assert.True(added.Contains(middleKey));
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:37,代码来源:ListDictionaryTests.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";
     ListDictionary ld; 
     Object itm;
     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++;
         ld = new ListDictionary();
         Console.WriteLine("1. Item() on empty dictionary");
         iCountTestcases++;
         cnt = ld.Count;
         Console.WriteLine("     - Item(null)");
         try 
         {
             itm = ld[null];
             iCountErrors++;
             Console.WriteLine("Err_0001a, no exception");
         }
         catch (ArgumentNullException ex) 
         {
             Console.WriteLine(" Expected exception: {0}", ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001b, unexpected exception: {0}", e.ToString());
         }
         iCountTestcases++;
         cnt = ld.Count;
         Console.WriteLine("     - Item(some_string)");
         itm = ld["some_string"];
         if (itm != null) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001c, returned non=null");
         }
         Console.WriteLine("2. add simple strings, access via Item(Object)");
         strLoc = "Loc_002oo"; 
         iCountTestcases++;
         cnt = ld.Count;
         int len = values.Length;
         for (int i = 0; i < len; i++) 
         {
             ld.Add(keys[i], values[i]);
         }
         if (ld.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, count is {0} instead of {1}", ld.Count, values.Length);
         } 
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
             if ( !ld.Contains(keys[i]) ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}b, doesn't contain key", i);
             }  
             iCountTestcases++;
             if (String.Compare(ld[keys[i]].ToString(), values[i], false) != 0)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}c, returned wrong value", i);
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co8694get_item_obj.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;
     IntlStrings intl;
     String strLoc = "Loc_000oo";
     ListDictionary ld; 
     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++;
         ld = new ListDictionary();
         Console.WriteLine("1. Contains() on empty dictionary");
         iCountTestcases++;
         Console.WriteLine("     - Contains(null)");
         try 
         {
             ld.Contains(null);
             iCountErrors++;
             Console.WriteLine("Err_0001a, no exception");
         }
         catch (ArgumentNullException ex) 
         {
             Console.WriteLine("  Expected exception: {0}", ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001b, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("     - Contains(some_object)");
         if ( ld.Contains("some_string") ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001c, empty dictionary contains some_object");
         }
         Console.WriteLine("2. add simple strings and check Contains()");
         strLoc = "Loc_002oo"; 
         iCountTestcases++;
         cnt = ld.Count;
         int len = values.Length;
         for (int i = 0; i < len; i++) 
         {
             ld.Add(keys[i], values[i]);
         }
         if (ld.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, count is {0} instead of {1}", ld.Count, values.Length);
         } 
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
             if ( ! ld.Contains(keys[i]) ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}b, doesn't contain \"{1}\"", i, keys[i]);
             }  
         }
         Console.WriteLine("3. add intl strings check Contains()");
         strLoc = "Loc_003oo"; 
         iCountTestcases++;
         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);
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co8686contains_obj.cs


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