Languages
[Edit]
EN

C# / .NET - generate list with 10 random numbers

6 points
Created by:
JustMike
26120

Random.Next method + List<T> class example

public static class RandomUtils
{
	public static List<int> generateList(int count)
	{
		Random random = new Random();
		List<int> values = new List<int>();

		for (int i = 0; i < count; ++i)
			values.Add(random.Next());

		return values;
	}
}

Example:

List<int> values = RandomUtils.generateList(10);

foreach (int entry in values)
	Console.WriteLine(entry);

Output:

490485272
864820117
1495826699
1735587819
842228568
570809745
1432321477
1467935517
1356326042
1627623506

References

  1. List<T> Class - Microsoft Docs
  2. Random.Next Method - Microsoft Docs
Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join