Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Lambda
- {
- class Program
- {
- private static IEnumerable<string> Countries = new List<string>()
- {
- "Albania", "Vietnam", "Angola", "Argentina", "Germany",
- "Bahrain", "Belarus", "Cuba", "France", "Greece", "Norway",
- "Poland", "Tajikistan", "United Kingdom", "Mauritius",
- "Haiti", "United States of America", "Ghana"
- };
- static void Main(string[] args)
- {
- ShowCountries();
- Console.ReadLine();
- }
- /// <summary>
- /// Use lambda expressions or linq to process the Countries sequence
- ///
- /// 1. Select only those countries whose name begins with an "A" or a "G"
- /// 2. Project each element of the seqeunce into an anonymous type containing two properties:
- /// Name (name of the country, in UPPERCASE)
- /// Length (length of the name of the country; e.g. length of Cuba is 4)
- /// 3. Sort by Length in descending order, then by Name in ascending order
- /// </summary>
- private static void ShowCountries()
- {
- var filteredCountries =
- foreach (var country in filteredCountries)
- {
- //Console.WriteLine("Name: {0}, Length:", country);
- Console.WriteLine("Name: {0}, Length: {1}", country.Name, country.Length);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment