Pre Course Home Next

C# Programming Interview Questions Tutorial

C# Linq

Q. In a list of integers, how you will select those numbers using Linq that are greater than any specific number, for example 5?
A. We will use lymbda syntax to write query, 

// let list of numbers
var numbers = new List<int>(){1, 2, 3, 4, 5, 6, 7, 8, 12, 44};

var result = numbers.Where(x => x > 5).ToList();

Q. How you can use group and count based on group?
A. We can write the query in below fashion.

// Lets say if we have a list of data and we want to group them by SampleId

var groupResult = list.GroupBy(x => x.SampleId).Select(x => new { SampleId = x.Key, Count = x.Count() }).ToList();

 

Pre Course Home Next