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


C# ArrayList.Where方法代码示例

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


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

示例1: Should_find_all_matches_in_a_populated_list

            public void Should_find_all_matches_in_a_populated_list()
            {
                var items = new ArrayList
                                {
                                    "Food",
                                    "",
                                    "Bar",
                                    null,
                                    "Base"
                                };

                var matches = new List<string>(items.Where(MatchNotNullOrEmptyDelegate()));
                Assert.AreEqual(3, matches.Count, "count is wrong");
                Assert.AreEqual(items[0], matches[0], "first item");
                Assert.AreEqual(items[2], matches[1], "second item");
                Assert.AreEqual(items[4], matches[2], "third item");
            }
开发者ID:mvbalaw,项目名称:MvbaCore,代码行数:17,代码来源:IEnumerableExtensionsTest.cs

示例2: Should_not_find_any_matches_in_an_empty_list

 public void Should_not_find_any_matches_in_an_empty_list()
 {
     var items = new ArrayList();
     Assert.IsFalse(items.Where(MatchNotNullOrEmptyDelegate()).Any(), "should not have returned any items");
 }
开发者ID:mvbalaw,项目名称:MvbaCore,代码行数:5,代码来源:IEnumerableExtensionsTest.cs

示例3: ExtractUniqueQueryTokensBasedOnOccurance

        private static void ExtractUniqueQueryTokensBasedOnOccurance(ArrayList<ArrayList<QueryToken>> disjuncts, 
                                                                    ArrayList<ArrayList<QueryToken>> finalQueryList,
                                                                    double twitterProfilerFrequencyThreshold, 
                                                                    ArrayList<ArrayList<QueryToken>> subsetsGrouped, 
                                                                    ArrayList<int> subsetsGroupedOccurance, 
                                                                    int maxOccurance)
        {            
            var subsetsWithMaxOccurance = subsetsGrouped
                                            .Where((x, idx) => subsetsGroupedOccurance[idx] == maxOccurance)
                                            .OrderBy(x => x.Count)
                                            .ToList();

            // remove subsets which are contained in other ones
            ArrayList<int> subsetsToRemove = new ArrayList<int>();
            for (int i = 0; i < subsetsWithMaxOccurance.Count(); ++i)
            {
                for (int j = i + 1; j < subsetsWithMaxOccurance.Count(); ++j)
                {
                    if (ContainsTokenSubset(subsetsWithMaxOccurance[i], subsetsWithMaxOccurance[j]))
                    {
                        subsetsToRemove.Add(i);
                        break;
                    }
                }                 
            }

            subsetsToRemove.Sort();
            subsetsToRemove.Reverse();

            foreach (var toRemove in subsetsToRemove.Distinct())
            {
                subsetsWithMaxOccurance.RemoveAt(toRemove);
            }
            subsetsToRemove.Clear();

            if (maxOccurance > 1) // perform twitter profiling
            {
                for (int i = 0; i < subsetsWithMaxOccurance.Count(); ++i)
                {
                    //twitter profiling
                    string searchQuery = TwitterProfiler.QueryTokensToStringConverter(subsetsWithMaxOccurance[i]);
                    double twitterProfilerFrequency = TwitterProfiler.ProfileFrequency(searchQuery);

                    if (Math.Round(twitterProfilerFrequency) == Convert.ToInt32(TwitterProfiler.InvalidReturns.Exception))
                    {
                        Console.WriteLine("\nError during twitter profiling: {0}!", TwitterProfiler.GetExceptionError());
                        System.Environment.Exit(1);
                    }

                    if (twitterProfilerFrequency < twitterProfilerFrequencyThreshold)
                    {
                        int disjunctsCountBeforeRemoval = disjuncts.Count();

                        // remove disjuncts from the original list that contain the selected subset
                        QueryConverterUtils.RemoveDisjunctsContainingSubsets(disjuncts, subsetsWithMaxOccurance[i]);

                        if (disjuncts.Count() < disjunctsCountBeforeRemoval)
                            finalQueryList.Add(subsetsWithMaxOccurance[i]);

                        if (disjuncts.Count() == 0)
                            return;
                        else
                        {
                            if (i >= (subsetsWithMaxOccurance.Count() - 1))
                            {
                                // find new possible subsets
                                QueryConverterUtils.ExtractUniqueQueryTokens(disjuncts, finalQueryList, twitterProfilerFrequencyThreshold);
                                return;
                            }
                        }
                    }
                    else
                    {
                        if (i >= (subsetsWithMaxOccurance.Count() - 1))
                        {
                            // select subsets with the first lower occurance
                            ArrayList<int> lowerOccurances = subsetsGroupedOccurance.FindAll(x => x < maxOccurance);
                            if (lowerOccurances.Count > 0)
                                maxOccurance = lowerOccurances.Max();
                            else
                                maxOccurance = 0;

                            if (maxOccurance < 1)
                                return;

                            QueryConverterUtils.ExtractUniqueQueryTokensBasedOnOccurance(disjuncts, finalQueryList, twitterProfilerFrequencyThreshold, subsetsGrouped, subsetsGroupedOccurance, maxOccurance);
                            if (disjuncts.Count() == 0)
                                return;
                        }
                    }
                }
            }
            else // if occurrence is 1 -> profiling not needed
            {
                foreach (var item in subsetsWithMaxOccurance)
                {
                    int disjunctsCountBeforeRemoval = disjuncts.Count();                    

                    // remove disjuncts from the original list that contain the selected subset
                    QueryConverterUtils.RemoveDisjunctsContainingSubsets(disjuncts, item);
//.........这里部分代码省略.........
开发者ID:SowaLabs,项目名称:QueryConverter,代码行数:101,代码来源:QueryConverterUtils.cs


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