I am trying to code a card game, and I'm making a shuffling system using a function, however it's telling me I need a closing bracket while all my brackets are closed. It's also asking me for an end-of-file or namespace definition. I'm using an online editor (dotnetfiddle.net) to edit this code, if that changes anything.
Here's my current code-
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World");
List<string> shuffle(List<string> l) { //ERROR 1: } expected
int count = l.Count-1;
List<string> ret = new List<string>();
int ind = 0;
Random rng = new Random();
string card = null;
while (count > -1) {
ind = rng.Next(0, count);
card = l[ind];
l.RemoveAt(ind);
ret.Add(card);
card = null;
count--;
}
return ret;
}
List<List<string>> playerHands = new List<List<string>>();
//💧🔥🌀🌱 (copypaste symbols)
List<string> deck = new List<string> {"1💧", "2💧", "3💧", "4💧", "5💧", "6💧", "7💧", "8💧", "9💧", "1🔥", "2🔥", "3🔥", "4🔥", "5🔥", "6🔥", "7🔥", "8🔥", "9🔥", "1🌀", "2🌀", "3🌀", "4🌀", "5🌀", "6🌀", "7🌀", "8🌀", "9🌀", "🌱1", "🌱2", "🌱3", "🌱4", "🌱5", "🌱6", "🌱7", "🌱8", "🌱9"};
List<string> sDeck = new List<string> {"R🔄", "S❌", "D🔳", "X⛈", "+✨", "A🌕", "A🌑"};
List<string> vDeck = new List<string> {"V◆", "V◇", "V◈"};
}
}//ERROR 2: Namespace, type, or end-of-file expected
Maybe it is related to the C# version you used.
Local functions are only allowed when using C# 7.
When I pasted your code in VS 2019, the compilation succeeded.
The only warning I have, is related to the function shuffle() that is declared but never used.
Also, always put your class in a namespace.