How to shuffle list in c# | Code2night.com
Code2night
  • Home
  • Blogs
  • Tutorial
  • Post Blog
  • Members
    • Register
    • Login
  1. Home
  2. Blogpost
14 May
2022

How to shuffle list in c#

1736

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#.

  • |
  • Shuffle List in c# , C#Net , AspNet

Comments

Follow Us On Social Media - Like Us On Facebook

Tags

LinkedinLogin
LinkedinProfile
GetLinkedinProfile
C#
Aspnet
MVC
Linkedin
ITextSharp
Export to Pdf
AspNet Core
AspNet
View to Pdf in Aspnet
Model Validation In ASPNET Core MVC 60
Model Validation
Model Validation In ASPNET Core MVC
Model Validation In ASPNET
Image Compression in AspNet
Compress Image in c#
AspNet MVC
Free Download for New Subscribers!

Subscribe and Click on Verify and Download for download link

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

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading

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 © 2023 by Code2night. All Rights Reserved

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