Start New Discussion within our Software Development Community

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.
Enjoy

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);
            Console.ReadKey();
        }
    }
}

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

The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.