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


C# Bag.Contains方法代码示例

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


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

示例1: Simple

        public void Simple()
        {
            var bag = new Bag<string>
                          {
                              "aa"
                          };

            Assert.AreEqual(bag.Count, 1);
            Assert.IsTrue(bag.Contains("aa"));
            Assert.AreEqual(bag["aa"], 1);

            bag.Add("bb");
            Assert.AreEqual(bag.Count, 2);
            Assert.IsTrue(bag.Contains("bb"));
            Assert.AreEqual(bag["bb"], 1);

            bag.Add("aa");
            Assert.AreEqual(bag.Count, 3);
            Assert.IsTrue(bag.Contains("aa"));
            Assert.AreEqual(bag["aa"], 2);

            bag.Add("cc", 3);
            Assert.AreEqual(bag.Count, 6);
            Assert.IsTrue(bag.Contains("cc"));
            Assert.AreEqual(bag["cc"], 3);

            bag.Add("cc", 2);

            Assert.AreEqual(bag.Count, 8);
            Assert.IsTrue(bag.Contains("cc"));
            Assert.AreEqual(bag["cc"], 5);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:32,代码来源:Add.cs

示例2: Simple

        public void Simple()
        {
            var bag = new Bag<string> { "aa", "bb", "aa", { "cc", 3 } };

            Assert.AreEqual(bag.Count, 6);

            Assert.IsTrue(bag.Remove("aa"));
            Assert.IsTrue(bag.Contains("aa"));
            Assert.AreEqual(bag["aa"], 1);
            Assert.AreEqual(bag.Count, 5);

            Assert.IsTrue(bag.Remove("aa"));
            Assert.IsFalse(bag.Contains("aa"));
            Assert.AreEqual(bag["aa"], 0);
            Assert.AreEqual(bag.Count, 4);

            Assert.IsFalse(bag.Remove("dd"));
            Assert.AreEqual(bag.Count, 4);

            Assert.IsTrue(bag.Remove("bb"));
            Assert.IsFalse(bag.Contains("bb"));
            Assert.AreEqual(bag["bb"], 0);
            Assert.AreEqual(bag.Count, 3);

            Assert.IsTrue(bag.Remove("cc"));
            Assert.IsTrue(bag.Contains("cc"));
            Assert.AreEqual(bag["cc"], 2);
            Assert.AreEqual(bag.Count, 2);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:29,代码来源:Remove.cs

示例3: TestAddRange

 public void TestAddRange()
 {
     Bag<string> target = new Bag<string>(Capacity);
     Bag<string> rangeOfElements = new Bag<string>(Capacity) { TestElement1, TestElement2, TestElement3 };
     target.AddRange(rangeOfElements);
     Assert.IsTrue(target.Contains(TestElement1) && target.Contains(TestElement2) && target.Contains(TestElement3));
 }
开发者ID:Kserol,项目名称:artemis_csharp-odb,代码行数:7,代码来源:TestBag.cs

示例4: TestAdd

        public void TestAdd()
        {
            // ReSharper disable UseObjectOrCollectionInitializer
            Bag<string> target = new Bag<string>(Capacity);
            // ReSharper restore UseObjectOrCollectionInitializer
            target.Add(TestElement1);
            target.Add(TestElement2);
            target.Add(TestElement3);

            Assert.IsTrue(target.Contains(TestElement1) && target.Contains(TestElement2) && target.Contains(TestElement3));
        }
开发者ID:Kserol,项目名称:artemis_csharp-odb,代码行数:11,代码来源:TestBag.cs

示例5: TestContains

 public void TestContains()
 {
     Bag<string> target = new Bag<string>(Capacity) { TestElement1, TestElement2, TestElement3 };
     const string Element = TestElement2;
     const bool Expected = true;
     bool actual = target.Contains(Element);
     Assert.AreEqual(Expected, actual);
 }
开发者ID:BaconSoap,项目名称:artemis_CSharp,代码行数:8,代码来源:TestBag.cs

示例6: TestNewBag

 public void TestNewBag()
 {
     Bag<string> b = new Bag<string>();
     Assert.AreEqual(0, b.Count);
     Assert.IsFalse(b.IsReadOnly);
     Assert.AreEqual(0, b.Count);
     Assert.IsFalse(b.Remove("foo"));
     Assert.IsFalse(b.Contains("bar"));
     try
     {
         b.CopyTo(new string[0], 0);
     }
     catch (Exception)
     {
         Assert.Fail("CopyTo() shouldn't touch parameter array if nothing to copy");
     }
 }
开发者ID:briandealwis,项目名称:gt,代码行数:17,代码来源:CollectionsTests.cs

示例7: TestAddAndRemove

        public void TestAddAndRemove()
        {
            Bag<string> b = new Bag<string>();
            Assert.AreEqual(0, b.Count);
            Assert.IsFalse(b.Contains("foo"));
            Assert.IsFalse(b.Contains("bar"));
            Assert.AreEqual(0, b.Occurrences("foo"));
            Assert.AreEqual(0, b.Occurrences("bar"));

            b.Add("foo");
            Assert.IsTrue(b.Contains("foo"));
            Assert.AreEqual(1, b.Count);
            Assert.AreEqual(1, b.Occurrences("foo"));
            Assert.AreEqual(0, b.Occurrences("bar"));

            b.Add("bar");
            Assert.IsTrue(b.Contains("foo"));
            Assert.IsTrue(b.Contains("bar"));
            Assert.AreEqual(2, b.Count);
            Assert.AreEqual(1, b.Occurrences("foo"));
            Assert.AreEqual(1, b.Occurrences("bar"));

            b.Add("foo");
            Assert.AreEqual(3, b.Count);
            Assert.IsTrue(b.Contains("foo"));
            Assert.IsTrue(b.Contains("bar"));
            Assert.IsFalse(b.Contains("baz"));
            Assert.AreEqual(2, b.Occurrences("foo"));
            Assert.AreEqual(1, b.Occurrences("bar"));

            Assert.IsTrue(b.Remove("foo"));
            Assert.AreEqual(2, b.Count);
            Assert.IsTrue(b.Contains("foo"));
            Assert.AreEqual(1, b.Occurrences("foo"));
            Assert.AreEqual(1, b.Occurrences("bar"));

            Assert.IsTrue(b.Remove("foo"));
            Assert.AreEqual(1, b.Count);
            Assert.IsFalse(b.Contains("foo"));
            Assert.AreEqual(0, b.Occurrences("foo"));
            Assert.AreEqual(1, b.Occurrences("bar"));

            Assert.IsFalse(b.Remove("foo"));
            Assert.AreEqual(1, b.Count);
            Assert.IsFalse(b.Contains("foo"));
            Assert.AreEqual(0, b.Occurrences("foo"));
            Assert.AreEqual(1, b.Occurrences("bar"));

            b.Clear();
            Assert.AreEqual(0, b.Count);
            Assert.IsFalse(b.Contains("foo"));
            Assert.AreEqual(0, b.Occurrences("foo"));
            Assert.AreEqual(0, b.Occurrences("bar"));
        }
开发者ID:briandealwis,项目名称:gt,代码行数:54,代码来源:CollectionsTests.cs

示例8: ClearExample

        public void ClearExample()
        {
            var bag = new Bag<string> {"cat", "dog", "canary"};

            // There should be 3 items in the bag.
            Assert.AreEqual(3, bag.Count);

            // Clear the bag
            bag.Clear();

            // The bag should be empty.
            Assert.AreEqual(0, bag.Count);

            // No cat here..
            Assert.IsFalse(bag.Contains("cat"));
        }
开发者ID:havok,项目名称:ngenerics,代码行数:16,代码来源:BagExamples.cs

示例9: ContainsExample

        public void ContainsExample()
        {
            var bag = new Bag<string> {"cat", "dog", "canary"};

            // bag does contain cat, dog and canary
            Assert.IsTrue(bag.Contains("cat"));
            Assert.IsTrue(bag.Contains("dog"));
            Assert.IsTrue(bag.Contains("canary"));
            // but not frog
            Assert.IsFalse(bag.Contains("frog"));
        }
开发者ID:havok,项目名称:ngenerics,代码行数:11,代码来源:BagExamples.cs


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