I need to "shuffle" an Array, I've found different ways of doing it but can't get any of them to work, this method seems straightforward enough, but I am getting the error "'KA_EMail_LeagueCup.Shuffle' is a 'type' but is used like a 'variable'".
I (think I) have created a Class called Shuffle.cs*, it has it's own tab and this is the code ...
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace KA_EMail_LeagueCup
- {
- class Shuffle
- {
- static Random _random = new Random();
- public static void Shuffle<T>(T[] array)
- {
- var random = _random;
- for (int i = array.Length; i > 1; i--)
- {
- // Pick random element to swap.
- int j = random.Next(i); // 0 <= j <= i-1
- // Swap.
- T tmp = array[j];
- array[j] = array[i - 1];
- array[i - 1] = tmp;
- }
- }
- }
- }
Expand|Select|Wrap|Line Numbers
- Shuffle(KA_Team);
... and this is where I get the error. OK, I realise that I need to go back to my video course and learn a few more basics, but I was getting on so well with this earlier that I just ploughed ahead !!!