我有一個靜態函數:訪問從靜態函數
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;
}
但每次我打電話過程中的功能,都會被重置,所以我想從靜態函數外部訪問列表。
有沒有辦法?
我想:
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;
}
但後來我得到一個指數是超出範圍的錯誤(不知道爲什麼)。
任何人都可以幫忙嗎?