Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,011 questions

51,958 answers

573 users

How to use Linq let to create complex query expression on int array in c#

2 Answers

0 votes
using System;
using System.Linq;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] array = { 1, 2, 3, 4, 5, 6 };

            var result = from element in array
                         let x = element * 30
                         where x >= 75
                         select x;

            foreach (var n in result)
                Console.WriteLine(n);
        }
    }
}


/*
run:

90
120
150
180

*/

 



answered Mar 4, 2017 by avibootz
0 votes
using System;
using System.Linq;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static int Calc(int value)
        {
            switch (value)
            {
                case 1:
                    return 1*2;
                case 2:
                    return 2*2;
                case 3:
                    return 3*2;
                case 4:
                    return 4*2;
                default:
                    return 0*2;
            }
        }
        static void Main(string[] args)
        {
            int[] array = { 1, 2, 3, 4 };

            var result = from element in array
                         let a = Calc(element)
                         let b = Calc(a)
                         select new { a, b };

            foreach (var n in result)
                Console.WriteLine(n);
        }
    }
}


/*
run:

{ a = 2, b = 4 }
{ a = 4, b = 8 }
{ a = 6, b = 0 }
{ a = 8, b = 0 }

*/

 



answered Mar 4, 2017 by avibootz
edited Mar 4, 2017 by avibootz
...