Some very basic LINQ

ddanbe 0 Tallied Votes 166 Views Share

LINQ is a great extension to the C# language!
But it can be terrifying at first.
So here is a little snippet just to get your feet wet.
You would normally use some sort of looping here.
See how easy it is to get some values from an array.

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

namespace LINQTesting
    class Program
        static void Main(string[] args)
            int[] MyAr = { 1, 2, 7, 4, 8, 3, -1, 9, -7, 3, 2, 5 };
            var MySum = MyAr.Sum();
            var MyMax = MyAr.Max();
            var MyMin = MyAr.Min<int>(); // if MyAr is not an integer array this will not work
            Console.WriteLine("Sum is: {0}, Maximum is: {1}, Minimum is: {2}", MySum, MyMax, MyMin);
claventure 0 Newbie Poster

So, compared to everyone else on the web complicating things,
this is helpful. Hey, thanks,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.