Q:

Write a program in C# to find the number of an array and the square of each number in LINQ Query

belongs to collection: All LINQ programs in C# with examples

0

Write a program in C# to find the number of an array and the square of each number in LINQ Query

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability.

using System;
using System.Linq;
using System.Collections.Generic;
 
class LinqExercise
{
    static void Main(string[] args)
    {
 
        var arr = new[] { 6,7,8,9 };
 
        var sqaure = from int Number in arr
                   let SqrNo = Number * Number                   
                     select new { Number, SqrNo };
 
        foreach (var a in sqaure)
            Console.WriteLine(a);
 
        Console.ReadLine();
    }
}

Result:

{ Number = 6, SqrNo = 36 }

{ Number = 7, SqrNo = 49 }

{ Number = 8, SqrNo = 64 }

{ Number = 9, SqrNo = 81 }

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a program in C# to display the top n-th reco... >>
<< Write a program in C# to create a list of numbers ...