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


Introduction

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


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. class LinqExercise
  6. {
  7. static void Main(string[] args)
  8. {
  9.  
  10. var arr = new[] { 6,7,8,9 };
  11.  
  12. var sqaure = from int Number in arr
  13. let SqrNo = Number * Number
  14. select new { Number, SqrNo };
  15.  
  16. foreach (var a in sqaure)
  17. Console.WriteLine(a);
  18.  
  19. Console.ReadLine();
  20. }
  21. }

Result

C# language techstudy.org

     





Related Topics




Popular Posts