Write a program in C# to find the positive numbers from a list of numbers using two where conditions 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.  
  4. class LinqExercise
  5. {
  6. static void Main()
  7. {
  8. int[] numbers = {
  9. 1, 3, 6, 9, 10, -4, -2, -3, -88, 12, 19, 14
  10. };
  11.  
  12. var nQuery =
  13. from VrNum in numbers
  14. where VrNum > 0
  15. where VrNum < 10
  16. select VrNum;
  17. Console.Write("\nThe numbers within the range of 1 to 10 are : \n");
  18. foreach (var VrNum in nQuery)
  19. {
  20. Console.Write("{0} ", VrNum);
  21. }
  22. Console.ReadLine();
  23. }
  24. }

Result

C# language techstudy.org

     





Related Topics




Popular Posts