Answer the question
In order to leave comments, you need to log in
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
string[] input = { "None", "20000", "30000", "45000", "50000", "75000" };
var output = input.Where(x => int.TryParse(x, out int t) ? t < 60000 : true);
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();
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();
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 questionAsk a Question
731 491 924 answers to any question