How to shuffle list in c# | Code2night.com
Code2night
  • Home
  • Blogs
  • Guest Posts
  • Tutorial
  • Post Blog
  • Register
  • Login
  1. Home
  2. Blogpost

How to shuffle list in c#

Date- May 14,2022

6155

C#Net AspNet

For ordering a list to specific order we use OrderBy but in some case we need the list to be ordered differently every time we try to access the list. In that case order by becomes useless as we don't want to follow any specific order. So for that purpose we use Random class like this 


List<Author> authors = new List<Author>  
{  
    new Author { Name = "Code", Book = "c# Programming", Price = 59.95 },  
    new Author { Name = "Code2Night", Book = "Shuffle", Price = 69.95 },  
    new Author { Name = "Blogs", Book = "Lists", Price = 79.95 }  
};   

var rnd = new Random();
authors = authors.OrderBy(item => rnd.Next()).ToList();

So, here we will use Random() for generating random order every time and which will shuffle the list every time you will try to access the data. This is how to shuffe list in c#.

Comments

Tags

Swagger UI
Swashbuckle
SwashbuckleAspNetCore
Rest API
Postman
Api Testing
ITextSharp
Export to Pdf
AspNet Core
AspNet
C#
View to Pdf in Aspnet
Scheduler
Fibonacci series in Java
Display Fibonacci Series
First C# Program
What is C?
C
C Programming
CodeLobster
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1760
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp Join Us On Facebook

Welcome To Code2night, A common place for sharing your programming knowledge,Blogs and Videos

  • Panipat
  • info@Code2night.com

Links

  • Home
  • Blogs
  • Tutorial
  • Post Blog

Popular Tags

Copyright © 2026 by Code2night. All Rights Reserved

  • Home
  • Blog
  • Login
  • SignUp
  • Contact
  • Terms & Conditions
  • Refund Policy
  • About Us
  • Privacy Policy
  • Json Beautifier
  • Guest Posts