I have a static function:
static string GenRan()
{
List<string> s = new List<string> {"a", "b"};
int r = Rand();
string a = null;
if (r == 1)
{
a += s[0];
s.RemoveAt(0);
}
if (r == 2)
{
a += s[1];
s.RemoveAt(1);
}
return a;
}
But everytime I call the function of course, the list is reset, so I would like to access the list from outside the static function.
Is there a way?
I tried:
static void Main(string[] args)
{
List<string> s = new List<string> {"a", "b"};
string out = GenRan(s);
}
static string GenRan(List<string> dict)
{
int r = Rand();
string a = null;
if (r == 1)
{
a += s[0];
s.RemoveAt(0);
}
if (r == 2)
{
a += s[1];
s.RemoveAt(1);
}
return a;
}
But then I get an Index is out of range error (not sure why).
Can anyone help?