Languages
[Edit]
EN

C# / .NET - get random key value element from dictionary

12 points
Created by:
Dharman
518

In C# / .NET Dictionary class is Java HashMap class equivalent - see this post.

Quick solution:

Note: below example uses Linq, so include it with: using System.Linq.

Take a look at the example below:

1. Linq and ElementAt method example

Edit

In this section you can find full example that uses Linq method.

Output:

Note: in above example Enuberable.ElementAt Linq method has been used to get element.

References:

Edit
  1. Random.Next Method - Microsoft Docs
  2. Dictionary<TKey,TValue> Class - Microsoft Docs
  3. Enumerable.ElementAt Method - Microsoft Docs
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

C# / .NET - random

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join