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


C# List.TakeWhile方法代码示例

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


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

示例1: Main

    static void Main()
    {
        var collection = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };

        int first = collection.FirstOrDefault(Even);

        Console.WriteLine(first);
        Console.WriteLine(collection.FirstOrDefault(x => x > 4));

        var allEven = collection.TakeWhile(Even);
        Console.WriteLine(string.Join(" ",allEven));
        Console.WriteLine(string.Join(" ", collection.TakeWhile(x => x < 10)));

        collection.ForEach(Console.WriteLine);
    }
开发者ID:alvelchev,项目名称:SoftUni,代码行数:15,代码来源:Test.cs

示例2: Main

 static void Main()
 {
     List<int> collection = new List<int>() { 1, 2, 3, 6, 11, 20 };
     Console.WriteLine(collection.FirstOrDefault(x => x > 7));
     Console.WriteLine(string.Join(", ", collection.TakeWhile(x => x < 5)));
     collection.ForEach(Console.WriteLine);
 }
开发者ID:petdakov,项目名称:SoftUni-Homeworks,代码行数:7,代码来源:Excercise.cs

示例3: Main

        static void Main(string[] args)
        {
            var nums = new List<int>() {1, 2, 3, 4, 5, 6, 7};

            var result = nums.TakeWhile(e => e < 6);

            Console.WriteLine(string.Join(", ", result));
        }
开发者ID:ivailojordanov,项目名称:Fundamental-Level,代码行数:8,代码来源:FuncMain.cs

示例4: filterByEnding

 private static List<Solution> filterByEnding(Solution end, List<Solution> solutions)
 {
     if (end != null)
     {
         solutions = solutions.TakeWhile(x => x != end).Where(end.DependsOn).ToList();
         solutions.Add(end);
     }
     return solutions;
 }
开发者ID:4lexm,项目名称:ripple,代码行数:9,代码来源:RipplePlanRequirements.cs

示例5: ProductRepository

        public ProductRepository()
        {
            _products = new List<Product>(new Product[]{
                new Product {Name = "Kayak", Category = "Watersports", Price = 275M},
                new Product {Name = "Lifejacket", Category = "Watersports", Price = 48.95M},
                new Product {Name = "Soccer ball", Category = "Soccer", Price = 19.50M},
                new Product {Name = "Corner flag", Category = "Soccer", Price = 34.95M}
            });

            _products.TakeWhile(p => p.Name == "Kayak");
        }
开发者ID:chavp,项目名称:HelloGithub,代码行数:11,代码来源:ProductRepository.cs

示例6: Lista

        public JsonResult Lista()
        {
            var lista = new List<int> ();

            for (int i = 0; i < 50; i++) {
                lista.Add (i);
            }

            var tes = lista.TakeWhile(a => a < 15).LastOrDefault();

            return Json(tes, JsonRequestBehavior.AllowGet);
        }
开发者ID:ecolinx,项目名称:testemvc,代码行数:12,代码来源:HomeController.cs

示例7: UlongPrimes

 public static IEnumerable<ulong> UlongPrimes() {
     var memoized = new List<ulong>();
     var primes = PotentialUlongPrimes().Where(x => {
             double sqrt = Math.Sqrt(x);
             return memoized
                 .TakeWhile(y => y <= sqrt)
                 .All(y => x % y != 0);
         });
     foreach (var prime in primes) {
         yield return prime;
         memoized.Add(prime);
     }
 }
开发者ID:garrett-carson,项目名称:ProjectEuler,代码行数:13,代码来源:PrimeNumbers.cs

示例8: Main

        static void Main()
        {
            List<int> list = new List<int>()
            {
                1, 12, 19, 13, 100, 1, 1000, 13, 13, 1
            };

            IEnumerable<int> smallNums = list.TakeWhile(n => n < 100);

            foreach (var num in smallNums)
            {
                Console.WriteLine(num);
            }
        }
开发者ID:krasi070,项目名称:OOP,代码行数:14,代码来源:Test.cs

示例9: Delete

        public int Delete(string name, string producer)
        {
            var productsWithGivenName = new List<Product>(
                productsByName[name]);
            var temp = productsWithGivenName.TakeWhile(x => x.Producer == producer);
            var count = temp.Count();

            foreach (var product in temp)
            {
                productsByName.Remove(product.Name);
                productsByPrice.Remove(product);
                productsByProducer.Remove(producer);
            }

            return count;
        }
开发者ID:niki-funky,项目名称:Telerik_Academy,代码行数:16,代码来源:ProductRepository.cs

示例10: Primes4

 public static IEnumerable<int> Primes4(int count)
 {
     var memoized = new List<int>();
     var primes = PotentialPrimes(count).Where(x =>
     {
         var sqrt = Math.Sqrt(x);
         return !memoized
                     .TakeWhile(y => y <= sqrt)
                     .Any(y => x % y == 0);
     });
     foreach (var prime in primes)
     {
         yield return prime;
         memoized.Add(prime);
     }
 }
开发者ID:lotekmedia,项目名称:codefundamentals,代码行数:16,代码来源:Program.cs

示例11: Get

		public static IEnumerable <long> Get ()
		{
			var temp = new List <long> ();
			var current = 1L;
			while (true)
			{
				current++;
				var sqrt = Math.Sqrt (current);
				if (temp
					.TakeWhile (x => x <= sqrt)
					.Any (x => current % x == 0))
					continue;

				temp.Add (current);
				yield return current;
			}
		}
开发者ID:juancri,项目名称:eulerproject,代码行数:17,代码来源:Primes.cs

示例12: Main

        static void Main()
        {
            Action<int> printNumberAction = Console.WriteLine;
            printNumberAction(10);

            var students = new List<Student>()
            {
                new Student("Pesho", 23),
                new Student("Sasho", 18),
                new Student("Ivan", 34)
            };
            Student ivan = students.FirstOrDef(Hasname);
            Console.WriteLine(ivan.Name + " " + ivan.Age);

            var nums = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            nums.ForEachH();
            var smallNums = nums.TakeWhile(IsSmallerThan);
            Console.WriteLine(String.Join(", ", smallNums));
        }
开发者ID:alagalia,项目名称:Object-Oriented-Programming,代码行数:19,代码来源:Program.cs

示例13: Append

 public void Append(TableDataDesc table)
 {
     var rows = new List<RowDesc>();
       foreach(var scriptedRow in table.ScriptedData)
       {
     var row = DataDescFactory.CreateRowDescriptor(scriptedRow, table.PrimaryColumns);
     rows.Add(row);
       }
       var gen = new RowScriptGen();
       //Header
       var header = rows.TakeWhile(r => false == r is InsertRowDesc);
       //_sb.Append(gen.GenerateScript(header));
       _sb.AppendFormat("{0}{1}", gen.GenerateScript(header), Environment.NewLine);
       //Data
       var data = rows.Where(r => r is InsertRowDesc).Select(r => r as InsertRowDesc);
       _sb.AppendFormat("{0}{1}", gen.GenerateMergeScript(data, true), Environment.NewLine);
       //Footer
       var footer = rows.Skip(header.Count() + data.Count());
       _sb.AppendFormat("{0}{1}", gen.GenerateScript(footer), Environment.NewLine);
 }
开发者ID:popovegor,项目名称:tools,代码行数:20,代码来源:TableScriptBuilder.cs

示例14: ProbeScreenBounds

        private IList<Rectangle> ProbeScreenBounds()
        {
            var screenBoundsList = new List<Rectangle>();

            foreach (Screen screen in Screen.AllScreens)
            {
                Rectangle currentBounds = DpiHelper.ConvertPixelsToDIPixels(screen.Bounds);

                if (screenBoundsList.Count == 0)
                {
                    screenBoundsList.Add(currentBounds);
                    continue;
                }

                int index = screenBoundsList.TakeWhile(bounds => (currentBounds.Top >= bounds.Top) && (currentBounds.Left >= bounds.Left)).Count();
                screenBoundsList.Insert(index, currentBounds);
            }

            return screenBoundsList;
        }
开发者ID:BravoAlpha,项目名称:WPFUtils,代码行数:20,代码来源:ScreenManager.cs

示例15: Generate

        public IEnumerable<long> Generate()
        {
            var primes = new List<long>();

            yield return 2;
            yield return 3;

            var value = 5L;
            var add4 = false;
            while(true)
            {
                var maxFactor = (int)Math.Sqrt(value) + 1;
                if (!primes.TakeWhile(prime => prime <= maxFactor).Any(prime => value % prime == 0))
                {
                    primes.Add(value);
                    yield return value;
                }

                value += (add4 ? 4 : 2);
                add4 = !add4;
            }
        }
开发者ID:ungood,项目名称:puzzles,代码行数:22,代码来源:SieveOfEratosthenes.cs


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