AsQueryable() in C#



AsQueryable() method is used to get an IQueryable reference.

Let us see an example to find sum of integer values.

Firstly, set an integer array.

var arr = new int[] { 100, 200, 300, 400 };

Now to find the sum, use the Queryable Sum() and AsQueryable() method.

Queryable.Sum(arr.AsQueryable());

The following is the complete code.

Example

 Live Demo

using System;
using System.Linq;
class Demo {
   static void Main() {
      var arr = new int[] { 100, 200, 300, 400 };
      int res = Queryable.Sum(arr.AsQueryable());
      Console.WriteLine("Sum: "+res);
   }
}

Output

Sum: 1000
Updated on: 2020-06-23T08:15:40+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements