Can someone please provide code for below question using Linq in C# ------------
ID: 3742876 • Letter: C
Question
Can someone please provide code for below question using Linq in C#
-----------------------------------------------------
ABC system sends the assets of the XYZ solutions for a periodical maintenance. Whenever any asset could not be repaired, they will be sent to scrap and hence the asset ids will not be continuous. Every week, certain set of assets will be sent for maintenance. Given an asset id "x" and another asset id "y", write a program using LINQ query to display the asset ids between the given x and y that are to be sent for maintenance this week.
Create a class Program.
Read the number of assets and create a list with asset id's
Get the start range and end range
Use LINQ query to find the id's between the range
Note:
Use select and where in the LINQ query
Input and Output Format:
Input consists of n number of assets.
Display the asset id's with in range.
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and the rest corresponds to output]
Sample Input/Output :
Enter total number of assets
5
Enter asset id's
23
25
12
41
30
Enter the range
12
30
Asset id's in the given range
23
25
Explanation / Answer
If you have any doubts, please give me comment...
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
// string collection
IList<int> assets = new List<int>();
Console.WriteLine("Enter total number of assets");
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter asset id's");
for(int i=0; i<n; i++){
int el = Convert.ToInt32(Console.ReadLine());
assets.Add(el);
}
Console.WriteLine("Enter the range");
int rangeStart = Convert.ToInt32(Console.ReadLine());
int rangeEnd = Convert.ToInt32(Console.ReadLine());
// LINQ Query Syntax
var result = from s in assets
where s>rangeStart && s<rangeEnd
select s;
Console.WriteLine("Asset id's in the given range");
foreach (var x in result)
{
Console.WriteLine(x);
}
}
}