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


C# Set.Contains方法代码示例

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


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

示例1: ContainsTest

 public void ContainsTest()
 {
     Set<int> set = new Set<int>();
     set.Add(1);
     Assert.IsTrue(set.Contains(1));
     Assert.IsFalse(set.Contains(2));
 }
开发者ID:Kirill-Andreev,项目名称:University,代码行数:7,代码来源:SetTest.cs

示例2: IsolateNodes

 public static List<CFGEdge> IsolateNodes(Set<CFGNode> nodes)
 {
     if (nodes.Count == 0)
     {
         return new List<CFGEdge>();
     }
     CFG graph = nodes[0].Graph;
     List<CFGEdge> removedEdges = new List<CFGEdge>();
     foreach (CFGNode node in nodes)
     {
         foreach (CFGEdge edge in graph.OutEdges(node))
         {
             if (!nodes.Contains(edge.Target))
             {
                 removedEdges.Add(edge);
             }
         }
         foreach (CFGEdge edge in graph.InEdges(node))
         {
             if (!nodes.Contains(edge.Source))
             {
                 removedEdges.Add(edge);
             }
         }
     }
     foreach (CFGEdge edge in removedEdges)
     {
         graph.RemoveEdge(edge);
     }
     return removedEdges;
 }
开发者ID:sidecut,项目名称:xaeios,代码行数:31,代码来源:GraphHelper.cs

示例3: SetTest

 public void SetTest()
 {
     var set = new Set<int>();
     set.Add(2);
     Assert.IsTrue(set.Contains(2));
     set.Delete(2);
     Assert.IsFalse(set.Contains(2));
 }
开发者ID:Ivan-Nebogatikov,项目名称:Homeworks,代码行数:8,代码来源:SetTests.cs

示例4: AddArrayToNonEmptySet

 public void AddArrayToNonEmptySet() {
    var set = new Set<int>();
    set.Add(11);
    set.Add(22);
    set.Add(new [] { 33, 44, 55 });
    Assert.Equals(5, set.Count);
    Assert.True(set.Contains(11));
    Assert.True(set.Contains(44));
 }
开发者ID:ManfredLange,项目名称:csUnit,代码行数:9,代码来源:SetTests.cs

示例5: TestIntersection

 public void TestIntersection()
 {
     var set =
         new Set<double>(value => 0d <= value && value < 2d).Intersection(
             new Set<double>(value => 1d < value && value <= 2d));
     Assert.IsFalse(set.Contains(0d));
     Assert.IsFalse(set.Contains(1d));
     Assert.IsFalse(set.Contains(2d));
 }
开发者ID:travis1230,项目名称:RosettaCodeData,代码行数:9,代码来源:set-of-real-numbers-2.cs

示例6: TestUnion

 public void TestUnion()
 {
     var set =
         new Set<double>(value => 0d < value && value <= 1d).Union(
             new Set<double>(value => 0d <= value && value < 2d));
     Assert.IsTrue(set.Contains(0d));
     Assert.IsTrue(set.Contains(1d));
     Assert.IsFalse(set.Contains(2d));
 }
开发者ID:travis1230,项目名称:RosettaCodeData,代码行数:9,代码来源:set-of-real-numbers-2.cs

示例7: ShouldContains

 public void ShouldContains()
 {
     var collection = new Set<string>();
     collection.Add("1");
     collection.Add("2");
     collection.Add(null);  // Ignored
     Assert.IsTrue(collection.Contains("1"));
     Assert.IsFalse(collection.Contains("Hello"));
     Assert.IsFalse(collection.Contains(null));
 }
开发者ID:p69,项目名称:magellan-framework,代码行数:10,代码来源:SetTests.cs

示例8: TestIfFindFindsTheValue

        public void TestIfFindFindsTheValue()
        {
            var set = new Set<int>();
            set.Add(5);
            set.Add(6);

            Assert.AreEqual(true, set.Contains(5));
            Assert.AreEqual(5, set.Find(5));
            Assert.AreEqual(false, set.Contains(7));
        }
开发者ID:radenkovn,项目名称:Telerik-Homework,代码行数:10,代码来源:SetTests.cs

示例9: ContainsStoryTwoAddsHaveDifferentTimes

 public void ContainsStoryTwoAddsHaveDifferentTimes()
 {
     var set = new Set<Story>();
     var story = new Story(new FrontpageItem { Title = "title", Link = "blah", Description = "shouldnt matter" });
     var story2 = new Story(new FrontpageItem { Title = "title", Link = "blah", Description = "diff but irrelevant" });
     set.Add(story);
     set.Add(story2);
     Assert.True(set.Contains(story));
     Assert.True(set.Contains(story2));
 }
开发者ID:tltjr,项目名称:HnNotify,代码行数:10,代码来源:StoryTests.cs

示例10: TestSet

 public static void TestSet()
 {
     Set<string> names = new Set<string>();
     names.Add("Jim");
     names.Add("Jones");
     Console.WriteLine("contains Jim? {0}", names.Contains("Jim"));
     Console.WriteLine("contains jim? {0}", names.Contains("jim"));
     names.Add("Jim");
     Console.WriteLine(names.Count);
     names.AddRange(new string[] { "Jones", "Jonny", "Michael" });
     Console.WriteLine(names.Count);
 }
开发者ID:jackfeichen,项目名称:Naive-Bayes-Classifier,代码行数:12,代码来源:Test.cs

示例11: Init

		public void Init(FdoCache cache, bool enableCancel)
		{
			CheckDisposed();

			m_cache = cache;
			m_btnCancel.Visible = enableCancel;
			Set<int> revIdxWs = new Set<int>(4);
			foreach (IReversalIndex ri in cache.LanguageProject.LexDbOA.ReversalIndexesOC)
				revIdxWs.Add(m_cache.ServiceLocator.WritingSystemManager.GetWsFromStr(ri.WritingSystem));
			// Include only the analysis writing systems chosen by the user.  See LT-7514 and LT-7239.
			Set<int> activeWs = new Set<int>(cache.ServiceLocator.WritingSystems.AnalysisWritingSystems.Select(wsObj => wsObj.Handle));
			m_cbWritingSystems.Sorted = true;
			m_cbWritingSystems.DisplayMember = "Name";
			IWritingSystem selectedWs = null;
			foreach (IWritingSystem ws in cache.ServiceLocator.WritingSystems.AllWritingSystems)
			{
				if (revIdxWs.Contains(ws.Handle))
				{
					AddLanguageForExistingRevIdx(ws);
					continue;
				}
				if (!activeWs.Contains(ws.Handle))
					continue;
				m_cbWritingSystems.Items.Add(ws);
				if (selectedWs == null && !m_revIdx.Contains(ws.LanguageSubtag))
					selectedWs = ws;
			}
			if (selectedWs != null)
				m_cbWritingSystems.SelectedItem = selectedWs;
			if (m_cbWritingSystems.Items.Count > 0 && m_cbWritingSystems.SelectedIndex < 0)
				m_cbWritingSystems.SelectedIndex = 0;
			if (!enableCancel && m_cbWritingSystems.Items.Count == 0)
				throw new ApplicationException("Cancel is disabled, but there are none to choose, so the user has no way to get out of this dialog.");
		}
开发者ID:bbriggs,项目名称:FieldWorks,代码行数:34,代码来源:CreateReversalIndexDlg.cs

示例12: Main

        public static void Main(string[] args)
        {
            var productsAndPrices = new OrderedMultiDictionary<int, string>(true);
            var rng = new Random();
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            for (int i = 0; i < 500000; i++)
            {
                var product = GenerateProduct(rng, i);
                var tokens = product.Split('|');
                var name = tokens[0].Trim();
                var price = int.Parse(tokens[1].Trim());
                productsAndPrices.Add(price, name);
            }

            Console.WriteLine("Seed time: " + stopwatch.Elapsed);
            stopwatch.Restart();
            Console.WriteLine("Query Start");
            var printed = new Set<int>();
            for (int i = 0; i < 10000; i++)
            {
                var startPrice = rng.Next(0, 100001);
                var endPrice = rng.Next(startPrice, 100001);
                var productsInRange = productsAndPrices.Range(startPrice, true, endPrice, true).Take(20);
                var count = productsInRange.Count();
                if (!printed.Contains(count))
                {
                    Console.WriteLine("{0} to {1} -> {2}", startPrice, endPrice, count);
                    printed.Add(count);
                }
            }

            Console.WriteLine("Query time: " + stopwatch.Elapsed);
            Console.WriteLine("All Done");
        }
开发者ID:peterkirilov,项目名称:SoftUni-1,代码行数:35,代码来源:ProductsInPriceRange.cs

示例13: eliminationAsk

        // function ELIMINATION-ASK(X, e, bn) returns a distribution over X
        /**
         * The ELIMINATION-ASK algorithm in Figure 14.11.
         * 
         * @param X
         *            the query variables.
         * @param e
         *            observed values for variables E.
         * @param bn
         *            a Bayes net with variables {X} &cup; E &cup; Y /* Y = hidden
         *            variables //
         * @return a distribution over the query variables.
         */

        public CategoricalDistribution eliminationAsk(RandomVariable[] X,
                                                      AssignmentProposition[] e, BayesianNetwork bn)
        {

            Set<RandomVariable> hidden = new Set<RandomVariable>();
            List<RandomVariable> VARS = new List<RandomVariable>();
            calculateVariables(X, e, bn, hidden, VARS);

            // factors <- []
            List<Factor> factors = new List<Factor>();
            // for each var in ORDER(bn.VARS) do
            foreach (RandomVariable var in order(bn, VARS))
            {
                // factors <- [MAKE-FACTOR(var, e) | factors]
                factors.Add(0, makeFactor(var, e, bn));
                // if var is hidden variable then factors <- SUM-OUT(var, factors)
                if (hidden.Contains(var))
                {
                    factors = sumOut(var, factors, bn);
                }
            }
            // return NORMALIZE(POINTWISE-PRODUCT(factors))
            Factor product = pointwiseProduct(factors);
            // Note: Want to ensure the order of the product matches the
            // query variables
            return ((ProbabilityTable) product.pointwiseProductPOS(_identity, X))
                .normalize();
        }
开发者ID:PaulMineau,项目名称:AIMA.Net,代码行数:42,代码来源:EliminationAsk.cs

示例14: ContainsStory

 public void ContainsStory()
 {
     var set = new Set<Story>();
     var story = new Story(new FrontpageItem { Title = "title", Link = "blah" });
     set.Add(story);
     Assert.True(set.Contains(story));
 }
开发者ID:tltjr,项目名称:HnNotify,代码行数:7,代码来源:StoryTests.cs

示例15: Contains_DataDrivenValues_AllShouldPass

        public void Contains_DataDrivenValues_AllShouldPass(int element, bool expected)
        {
            var set = new Set<int>(new[] { 1, 3, 5, 7, 9 });
            bool actual = set.Contains(element);

            Assert.Equal(expected, actual);
        }
开发者ID:Confirmit,项目名称:Students,代码行数:7,代码来源:SetTests.cs


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