LINQ in C Sharp
With LINQ, you can query data from sql, object collections, xml, json or any other format Example In below example, we are using Linq syntax to fire a query on String array. Similarly we can use linq to query different types of data as well. For example - let say we have a list of car objects and we want to sort those objects based on price. Then we can use below syntax
var orderByPrice = from car in carList
orderby car.price
select car;
using System.Linq;
using System;
namespace mstest
{
[TestClass]
public class UnitTest1 : Base
{
[TestMethod]
public void TestMethod1()
{
string[] cities = { "brisbane","perth", "sydney" };
var citylist = from city in cities
where city.Contains('y')
select city;
foreach (var city in citylist)
Console.WriteLine(city);
}
}
}
Here is the output of above example.
Web development and Automation testing
solutions delivered!!