K
K
kek1232017-04-18 15:27:33
.NET
kek123, 2017-04-18 15:27:33

How to write linq expression?

There is a string list with the values ​​"None", "20000", "30000", "45000", "50000", "75000"
We need to filter out values ​​that are greater than the value maxSum = 60000.
The result should be: "None", "20000 ", "30000", "45000", "50000"
How to write a linq query correctly?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Roman, 2017-04-18
@yarosroman

string[] input = { "None", "20000", "30000", "45000", "50000", "75000" };
var output = input.Where(x => int.TryParse(x, out int t) ? t < 60000 : true);

D
Dmitry Eremin, 2017-04-18
@EreminD

List<string> lst = new List<string> { "Нет", "20000", "30000", "45000", "50000", "75000" };

List<string> res = lst.Where(x => !int.TryParse(x, out int n) || int.Parse(x) < maxSum ).ToList();

Y
yorick_kiev_ua, 2017-04-18
@yorick_kiev_ua

string[] arr = { "None", "20000", "30000", "45000", "50000", "75000" };
int i;
//var x = arr.Where(_ => !int.TryParse(_, out i) || int.Parse(_) < 60000).ToList();
var x = arr.Where(_ => !int.TryParse(_, out i) || i < 60000).ToList();

T
Tom Nolane, 2017-04-18
@tomnolane

string[] input = { "Нет", "20000", "30000", "45000", "50000", "75000" }; int t; const int maxSum = 60000;
var output = (from f in input where int.TryParse(f, out t) ? t < maxSum : true select f).ToArray();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question