Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - using System;
 - using System.Collections.Generic;
 - using System.Linq;
 - namespace Linq_A
 - {
 - class Program
 - {
 - static void Main(string[] args)
 - {
 - //giochi è una sequenza di elementi stringhe
 - string[] giochi = { "Borderlands 1", "Borderlands 2", "Borderlands 3", "Destiny 1", "Destiny 2", "Doom" };
 - //il risultato è una sequenza (IEnumerable)
 - //sintassi fluente (fluent)
 - var sequenzaRisultato = giochi.Where(gioco => gioco.StartsWith("Bord"));
 - //method sintax, query expression sintax
 - var ris2 = from gioco in giochi where gioco.Contains("Borderlands") select gioco;
 - sequenzaRisultato = giochi
 - .Where(gioco => gioco.StartsWith("Bord"))
 - .OrderBy(gioco => gioco.Length)
 - .Select(gioco => gioco.ToUpper());
 - //il risultato in quanto IEnumerable è "consumabile" con un foreach
 - foreach (string gioco in sequenzaRisultato) Console.WriteLine(gioco);
 - //foreach (string gioco in ris2) Console.WriteLine(gioco);
 - }
 - }
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment