0

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();
        }
    }
}
2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by claventure
0

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

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.