Run Code  | API  | Code Wall  | Misc  | Feedback  | Login  | Theme  | Privacy  | Patreon 

Some linq examples

// Some linq examples
//Rextester.Program.Main is the entry point for your code. Don't change it.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            List<string> output = new List<string> {"","","","","","","","","","",""};
List<Double> list = new List<Double> { 1, 3, 2, 4, 5,6, 0, 1.5 };
            string o = "The full list : ";
            foreach(var a in list) {
                o = o + a + ", ";
            }
            Console.WriteLine(o);
            
var query1 = from num in list
             where num < 3
             select num;

            o = "Less than 3   : ";
            foreach(var a in query1) {
                o = o + a + ", ";
            }
                        Console.WriteLine(o);
            
var query2 = from num in query1
             where num > 1
             select num;
            
            o = "Greater than 1: ";
            foreach(var a in query2) {
                o = o + a + ", ";
            }
                        Console.WriteLine(o);

var query3 = from num1 in query1
             from num2 in query2
             select num1+num2;
            
            o = "Sum           : ";
            foreach(var a in query3) {
                o = o + a + ", ";
            }
                        Console.WriteLine(o);
        }
    }
}
 run  | edit  | history  | help 0