Some very basic LINQ


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.

About the Author

Have programmed in Modula-2 on a professional basis in the eighties. Now I am quite fond of C# AND Python!

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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.