Guest User

Untitled

a guest
Oct 15th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Lambda
  7. {
  8.     class Program
  9.     {
  10.         private static IEnumerable<string> Countries = new List<string>()
  11.         {
  12.             "Albania", "Vietnam", "Angola", "Argentina", "Germany",
  13.             "Bahrain", "Belarus", "Cuba", "France", "Greece", "Norway",
  14.             "Poland", "Tajikistan", "United Kingdom", "Mauritius",
  15.             "Haiti", "United States of America", "Ghana"
  16.         };
  17.  
  18.         static void Main(string[] args)
  19.         {
  20.             ShowCountries();
  21.  
  22.             Console.ReadLine();
  23.         }
  24.  
  25.         /// <summary>
  26.         /// Use lambda expressions or linq to process the Countries sequence
  27.         ///
  28.         ///     1. Select only those countries whose name begins with an "A" or a "G"
  29.         ///     2. Project each element of the seqeunce into an anonymous type containing two properties:
  30.         ///         Name (name of the country, in UPPERCASE)
  31.         ///         Length (length of the name of the country; e.g. length of Cuba is 4)
  32.         ///     3. Sort by Length in descending order, then by Name in ascending order
  33.         /// </summary>
  34.         private static void ShowCountries()
  35.         {
  36.             var filteredCountries =
  37.      
  38.  
  39.             foreach (var country in filteredCountries)
  40.             {
  41.                 //Console.WriteLine("Name: {0}, Length:", country);
  42.                 Console.WriteLine("Name: {0}, Length: {1}", country.Name, country.Length);
  43.             }
  44.         }
  45.     }
  46. }
Add Comment
Please, Sign In to add comment