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

  • Home
  • SEARCH
  • 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 8104893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:00:20+00:00 2026-06-06T00:00:20+00:00

I am trying the following codes to suffle the elements of an ArrayList –

  • 0

I am trying the following codes to suffle the elements of an ArrayList– questionsAndSeperators. I am doing this with two ways.
Method 1:-

List<Question> questionList = this.questionsAndSeperators.Cast<Question>().ToList();

Random rng = new Random();
int questionCount = questionList.Count;
while (questionCount > 1)
{
   questionCount--;
   int index = rng.Next(questionCount + 1);
   Question value = questionList[index];
   questionList[index] = questionList[questionCount];
   questionList[questionCount] = value;
}

Method 2:-

ArrayList questionList = this.questionsAndSeperators;

Random rng = new Random();
int questionCount = questionList.Count;
while (questionCount > 1)
{
   questionCount--;
   int index = rng.Next(questionCount + 1);
   object value = questionList[index];
   questionList[index] = questionList[questionCount];
   questionList[questionCount] = value;
}

Here Question is a class.
Method 2 is working fine and suffling the elements of questionsAndSeperators, but Method 1 is not able to suffle the elements of questionsAndSeperators. What is the problem with Method 1??
Am I doing something wrong in method 1?

  • 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-06T00:00:22+00:00Added an answer on June 6, 2026 at 12:00 am

    In Method 1 you create a new List<Question> with all elements of this.questionsAndSeperators.
    Then you shuffle all elements of the new List<Question>. But you don’t shuffle the elements of this.questionsAndSeperators because its another array.

    In Method 2 you access the ArrayList directly and you shuffle the elements of the ArrayList.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to multiply two 16 bit numbers with the following NASM codes: mov
In the following let's say zip codes I am trying to exclude the 33333-
I'm trying to make long codes short. The original codes does something following: using
I am trying to retrieve the values of 'Title' using the following codes: private
The following codes does not work, I am trying to retrive TR strings from
I was trying to get the property name with following codes and hit the
The following simple codes show how I'm trying to keep white space in my
I'm trying to get ARGB components from CGBitmapContext with the following codes: -(id) initWithImage:
I've been trying to use the venues/add api as in the following codes: private
I'm trying to figure out why the following codes doesn't return the same result:

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.