Question

I was sure I had done this right, I'm aware of other topics, but as I felt I did it right I'm not sure what error to look for.

What I am trying to do is assign the array of x size a number 1 to x then shuffle it, right now i haev just hard coded x to be 8 until I get the basics down, I am a novice when it comes to c# so i seem to be struggling with some of the most basic concepts.

I have been playing with it now I developed this issue

'ArrayAssignment.Program.Shuffle<sort>(int[])' must declare a body because it is not marked abstract, extern, or partial Line:18 column: 28

Any help would be appreciated

    class NumberShuffle
    {
    int i;
    int j;
    //array
    int[] sort = new int[8];                  

    static Random _random = new Random();

    public static void Shuffle<int>(int[] sort);


    public void RunProgram()
    {


       for (int i = 0; i < 8; i++)
       {
           sort[i] = i + 1;
       }
       var random = _random;
       for (int i = sort.Length; i > 1; i--)
       {
           int j = random.Next(i);
           int tmp = sort[j];
           sort[j] = sort[i - 1];
           sort[i - 1] = tmp;

       }


       for (int i = 0; i < 8; i++)
       {
           Console.WriteLine(sort[i]);
       }

       }


          static void Main(string[] args)
        {
        NumberShuffle myNumberShuffle = new NumberShuffle();
        myNumberShuffle.RunProgram();

        Console.WriteLine("\n\n===============================");
        Console.WriteLine("NumberShuffle: Press any key to finish");
        Console.ReadKey();

        }
        }
Was it helpful?

Solution

Remove this string public static void Shuffle<int>(int[] sort);

OTHER TIPS

Well, as the complier tells you (...Shuffle(int[]) must declare a body because it is not marked abstract, extern, or partial...), you should implement method's body:

// Incorrect: the method requires body
// public static void Shuffle<int>(int[] sort);

public static void Shuffle<int>(int[] sort) {
  // Put necessary code here
}

Or if you actually don't need Shuffle method, you can safely remove it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top