Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7966321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:23:36+00:00 2026-06-04T06:23:36+00:00

Random r = new Random(); List<object> myList = new List<object>(); for (int i =

  • 0
Random r = new Random();
List<object> myList = new List<object>();

for (int i = 0; i < 100; i++)
  myList.Add(new { A = r.Next(), B = r.Next() });

myList.Sort( (obj1, obj2) => obj1.A.CompareTo(obj2.A) );

The above code defines a generic List an populates it with 100 anonymous variables with two members, A and B.

Let’s say I want to sort myList on A. The final line attempts to sort the list, however this code clearly doesn’t compile because the compiler doesn’t know what the list of objects contains.

Without using LINQ, is it possible to somehow sort this list using a lambda or similar?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:23:38+00:00Added an answer on June 4, 2026 at 6:23 am

    It is possible to sort it without LINQ, as long as you manage to declare your list as that of a List of objects of anonymous type using the var syntax, or are willing to use dynamic:

    Random r = new Random();
    List<dynamic> myList = new List<object>();
    
    for (int i = 0; i < 100; i++)
        myList.Add(new { A = r.Next(), B = r.Next() });
    
    myList.Sort( (obj1, obj2) => obj1.A.CompareTo(obj2.A) );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import java.util.Random class Kostka { val rand = new Random(System.currentTimeMillis()) val value: List[Int] =
I use this code to generate a random number. Random R = new Random(0);
I have the following code: var items = new List<string> {1, 2, 3}; //
it is possible using a list like private LinkedList<Object> deckOfCards = new LinkedList<Object>(); for
Im new to MySql, and I need to insert into table 10000 random 2-digit
I am using c++11 new <random> header in my application and in one class
How can I retrive random random ItemIDs from the list of existing ItemIDs in
Here's a random question. I have an object called Monkey, and an object called
I'm trying to create a new instance of a custom object inside a for
I have a list and I want to assign a random element from that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.