Advertisement
renurtt

Untitled

Sep 20th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace linq
  6. {
  7.     using System.IO;
  8.     internal class Program
  9.     {
  10.         public static string[] GetAllStrings(string path)
  11.         {
  12.             string k;
  13.             using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
  14.                 using (StreamReader sw = new StreamReader(fs))
  15.                 {
  16.                     k = sw.ReadToEnd();
  17.                 }
  18.             return k.Split('\n');
  19.         }
  20.         public static void Main(string[] args)
  21.         {
  22.             string [] words = GetAllStrings("/Users/renurt/RiderProjects/files_refresh/wordlist.txt");
  23.            
  24.             IEnumerable<string> beginsWithBa = from n in words where n.StartsWith("ba") where n.Length>2 orderby n[n.Length-2], n.Length descending select n;
  25.             foreach (var word in beginsWithBa)
  26.             {
  27.                 Console.WriteLine(word);
  28.             }
  29.  
  30.             IEnumerable<IGrouping<int, string>> containsCan = from n in words where n.Contains("can") group n by n.IndexOf("can");
  31.  
  32.             foreach (IGrouping<int, string> group in containsCan)
  33.             {
  34.                 Console.WriteLine(group.Key+":");
  35.                 foreach (string word in group)
  36.                 {
  37.                     //Console.WriteLine(word);
  38.                 }
  39.             }
  40.  
  41.             var OK = from n in words
  42.                 where n.Contains("su")
  43.                 from k in new int[] {1, 2}
  44.                 select k + n
  45.                 into l
  46.                 where l[1] == 'r'| l[1] == 'm'
  47.                 orderby l.Length group l by l.Length;
  48.            
  49.             foreach (var group in OK)
  50.             {
  51.                 Console.WriteLine(group.Key + ":");
  52.                 foreach (string word in group)
  53.                 {
  54.                     Console.WriteLine(word);
  55.                 }
  56.             }
  57.  
  58.             var mk = words.Where(t => t.StartsWith("nas"));
  59.             double s = 4.34234;
  60.             Console.WriteLine($"{s:0.0010}");
  61.             Console.WriteLine($"{s:f2}");
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement