Advertisement
bero_0401

Linq3

Oct 4th, 2024
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | Source Code | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using System;
  6. using revision;
  7.  
  8.  
  9. public class Program
  10. {
  11.  
  12.  
  13.     static void Main(String[] args)
  14.     {
  15.         // Quantifiers (All , Any, Contains)   =>   return boolean var
  16.         var lst = new List<int> { -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  17.         //Console.WriteLine(lst.Any(x => x < 0));
  18.         //Console.WriteLine(lst.All(x => x > 0));
  19.         //Console.WriteLine(lst.Contains(5));
  20.  
  21.  
  22.         // Partitioning  (Skip, SkipWhile, Take, TakeWhile, Chunck)
  23.         var result = lst.Skip(4).Take(4);
  24.         result = lst.SkipWhile(x => x < 0);
  25.         result = lst.TakeWhile(x => x < 0);
  26.         //foreach(int x in result) Console.WriteLine(x);
  27.  
  28.  
  29.         var chunks = lst.Chunk(3);
  30.         //foreach (var chunk in chunks)
  31.         //{
  32.         //    foreach (var item in chunk)
  33.         //    {
  34.         //        Console.Write($"{item} ");
  35.         //    }
  36.         //    Console.WriteLine();
  37.         //}
  38.  
  39.  
  40.  
  41.         // Set Operations (Distinct, DistinctBy, Except, ExceptBy, Intersect, IntersectBy, Union, UnionBy)
  42.         var A = new List<int> { 1, 1, 2, 3, 3, 4, 5, 6 };
  43.         var B = new List<int> { 4, 5, 6, 7, 8, 9 };
  44.         var C = A.Union(B);
  45.         C = A.Intersect(B);
  46.         C = A.Except(B);
  47.         C = A.Distinct();
  48.  
  49.         foreach (int x in C) Console.WriteLine(x);
  50.  
  51.     }
  52.  
  53.  
  54. }
  55.  
  56.  
  57.  
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement