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 3669806
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:17:15+00:00 2026-05-19T02:17:15+00:00

I have problem with List<T>.Reverse() and Reverse(this IEnumerable<TSource> source) . Look to the code:

  • 0

I have problem with List<T>.Reverse() and Reverse(this IEnumerable<TSource> source).
Look to the code:

  // Part 1
  List<int> list = new List<int> { 1, 2, 3 };

  foreach (int x in list)
    Console.Write(x);

  Console.WriteLine();

  list.Reverse();

  foreach (int x in list)
    Console.Write(x);

  Console.WriteLine();
  list.Reverse();

  // Part2
  IList<int> ilist = list;

  foreach (int x in list)
    Console.Write(x);      

  Console.WriteLine();

  ilist.Reverse();

  foreach (int x in ilist)
    Console.Write(x);

  Console.WriteLine();

  ilist.Reverse();

My result:

123
321
123
123

because Reverse()-Part1 is List<T>.Reverse(), Reverse()-Part2 is Reverse(this IEnumerable<TSource> source)
I want execute List<int>.Reverse() in Part2 for IList<int>. How I can do it?

  • 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-05-19T02:17:16+00:00Added an answer on May 19, 2026 at 2:17 am

    IList<int> doesn’t have a Reverse method, so it uses the extension method. The only way to use List<T>.Reverse on your IList<int> reference is to cast or convert it to a List<int>. Casting will only work if you’re sure that it’s really a List<int> in the first place:

    IList<int> abstractList;
    var concreteList = (List<int>)abstractList;
    concreteList.Reverse();
    

    Another option would be to create a List<int> from your IList<int> instance, rather than assuming it already is a List<int>:

    IList<int> abstractList;
    var concreteList = new List<int>(abstractList);
    concreteList.Reverse();
    

    The reason that the Reverse extension method doesn’t actually affect the underlying list is because it operates on IEnumerable<T>, which isn’t necessarily writeable (none of the Enumerable extension methods make changes to the original collection, they return a new collection).

    To use this version of Reverse, just use the product of the Reverse call, rather than the original list:

    IList<int> abstractList;
    IEnumerable<int> reversedList = abstractList.Reverse();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have found this example on StackOverflow: var people = new List<Person> { new
I have a problem with the following code: public static void RestoreToolStripMenuItem(ToolStripMenuItem item, List<string>.Enumerator
I have a Foo object, and a std::list holding instances of it. My problem
I do not have problem as such but I am quite new to Ruby.
My problem is simple: I have a long list of elements that I want
n00b problem- I am trying to have a list show the most recent entry
i have a problem implementing a list action with its own route. here is
I have entity Problem mapped using many-to-many to entity Tag (Problem has a list
I have problem with session and query execution, please see code below. class A

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.