Skip to content
Fix Code Error

How to Sort a List by a property in the object

March 13, 2021 by Code Error
Posted By: Anonymous

I have a class called Order which has properties such as OrderId, OrderDate, Quantity, and Total. I have a list of this Order class:

List<Order> objListOrder = new List<Order>();
GetOrderList(objListOrder); // fill list of orders

Now I want to sort the list based on one property of the Order object, for example I need to sort it by the order date or order id.

How can i do this in C#?

Solution

The easiest way I can think of is to use Linq:

List<Order> SortedList = objListOrder.OrderBy(o=>o.OrderDate).ToList();
Answered By: Anonymous

Related Articles

  • How to filter a RecyclerView with a SearchView
  • LINQ query to include the parent name in the child item
  • Best way to extract messy HTML tables using BeautifulSoup
  • Ember data parent / child models and json
  • How to Join to first row
  • How can I generate correct detail url using aurelia router?
  • how to make column bool data to be true with the…
  • Sum columns, count rows, with multiple tables to…
  • Vue - Deep watch change of array of objects, either…
  • Vue js combining the elements from two components
  • How to execute raw queries with Laravel 5.1?
  • how to get v-for loop data from outside of loop also…
  • Reloading an Element After Data Is Loaded in Polymer
  • Compare array of object values if equals add it total
  • Ember.js Rendering template while waiting for data
  • Ember Data DS.Store.filter() not working on nested routes?
  • How to aggregate values from a list and display in…
  • LINQ left join generates wrong SQL query
  • Bootstrap - center child when parent isn't centered…
  • How to blur the background after click on the button…
  • How to send file by email from Firebase Storage…
  • How to conditionally calculate the running total…
  • Display vue component in laravel blade template
  • Parent data not defined in vue.js component
  • Ember.js Computed property does not update hasMany…
  • VueJS accessing data from component in root Vue instance
  • Remove duplicated objects from array but also…
  • .Net Core 3.1 Entity Framework Slow Query Problem
  • Vuex and reactivity in list rendering
  • Convert array to nested JSON object - Angular Material tree
  • Routing & events - backboneJS
  • Group array of objects by multiple keys using d3.groups
  • Keeping time and time difference in realtime in Vue
  • SUM a column then SUBTRACT the SUM of another column…
  • vuejs :disabled doesn't work
  • Transform item receipt looping forever
  • Calculate a Running Total in SQL Server
  • How would I refresh a Backgrid table with new data?
  • Using LINQ to find item in a List but get "Value…
  • D3 chart integration into Vuejs
  • How do I parse a string in Python and obtain…
  • Is this request generated by EF Core buggy or is it my code?
  • How to pivot on multiple rows and create a…
  • (Next/react) SWR refresh from button click in child…
  • Create a trigger that subtracts 1 from a column in…
  • Populate an array with objects in Angular 8
  • Get selected item and its count
  • Adding up BigDecimals using Streams
  • Custom date picker in Vuetify
  • $emit an event from child to parent component Vue 2
  • FIND_IN_SET() vs IN()
  • dc.js filter by row values
  • Cart bulk quantity discount for specific product tag…
  • tidyverse: append rows of totals in summary output
  • JavaScript: Comparing Two Arrays and Replacing Objects
  • How to use filter result which is a promise in an…
  • Using jQWidgets in Aurelia
  • Multi-statement Table Valued Function vs Inline…
  • How to get dynamic column data linq
  • Animating Elements in One by One
  • Convert Java Date to UTC String
  • Select with sum() case
  • How to perform aggregation in two different columns…
  • How to add a gap between ExpansionPanels in flutter?
  • React function keeps refreshing page causing huge…
  • Dynamic LINQ OrderBy on IEnumerable / IQueryable
  • How do I update the quantity without duplicate in redux?
  • Create a custom hidden field in backend product…
  • How do I push items into an array in the data object…
  • Getting the difference between two Dates…
  • How to get data from JSON for chart.js, using vue.js
  • Accessing Firebase from Polymer Element
  • Is there a way to get two specific data together in…
  • Binance API Python - How to use a specific output
  • Chunk and excel Laravel
  • What is the best way to paginate results in SQL Server
  • Angularjs action on click of button
  • Why is there no SortedList in Java?
  • Backbone.js Link Model and VIew
  • How to convert java.util.Date to java.sql.Date?
  • How can we load color from a sequential scale into a…
  • How can I get individual amounts of stock levels for…
  • Filtering or removing array objects from the DTO…
  • labeling rows in dataframe, based on dynamic conditions
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • Error adding List of Map to Firebase: Flutter
  • Add key value pair to List
  • Can I get a specific JSON value by Id?
  • So can't use weasyprint what is the best thing to do?
  • The number of method references in a .dex file…
  • How To Edit Date and Time Picker Vuejs Vuetify From…
  • How can I do an OrderBy with a dynamic string parameter?
  • Material-ui Table sorting not working reactjs
  • Fix a compile error when comparing a T[keyof T] and…
  • Vue Draggable Second List Does Not Keep Sort
  • Vue js v-bind to function not working?
  • Vue 2 : Cannot read property id of null
  • Subroutes in Next Js
  • Update nested object in array in ReactJs
  • Polymer - Conditional Template

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How to parse XML and count instances of a particular node attribute?

Next Post:

How to return dictionary keys as a list in Python?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error