1
public class BatchProcess
    {
        public string process { get; set; }
        public DateTime runtime { get; set; }
        public bool running { get; set; }
    }

So I have a list of these guys - List<BatchProcess> list.

How would I sort based one each of those columns? I've heard I can do it with LINQ but I'm so bad with LINQ. How would that look?

Thanks.

4 Answers 4

6

You could sort by runtime, for example, via:

var orderedByRuntime = list.OrderBy(p => p.runtime);

If you wanted to sort by "process" in descending order, you can use:

var orderedByProcessDesc = list.OrderByDecending(p => p.process);
Sign up to request clarification or add additional context in comments.

Comments

2

Here's an example of using LINQ (lambda syntax) to create a list that's sorted by process.

var listByProcess = list.OrderBy(bp => bp.process);

Comments

2

Use OrderBy:

var sortedList = list.OrderBy(p => p.runtime).ToList();

Comments

0

If you want to sort by all of them, as it seems this is what you are asking you can just do the following

var sorted = list.OrderBy(p => p.process).ThenBy(r => r.runtime);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.