Im trying to make a seating chart and the way im going about it doesn't seem to be working and i really need some help with assigning a value (each value will be a seat number on a little chart i made) to a variable (a students name). The problem i keep having is im trying to use a list to store what seats (numbers) i already have assigned to one student. Then if the seat value is already in the list, it should go back to get a new value and the repeat the checking process to see if the new value is taken and so on. in python it would just be something as simple as
def main():
x = Random.randint(1,20)
main() <----this go back to type function is what i need to know in c#
below is my code in c#
public void Button_Click(object sender, EventArgs e)
{
int a = getValue();
int b = getValue();
int c = getValue();
int d = getValue();
int ee = getValue();
int f = getValue();
int g = getValue();
int h = getValue();
int i = getValue();
int ff = getValue();
int gg = getValue();
int hh = getValue();
int ii = getValue();
int j = getValue();
int k = getValue();
int l = getValue();
int m = getValue();
int n = getValue();
int o = getValue();
int p = getValue();
int q = getValue();
int r = getValue();
int s = getValue();
int t = getValue();
int u = getValue();
int v = getValue();
int w = getValue();
int x = getValue();
int y = getValue();
int z = getValue();
int AA = getValue();
int BB = getValue();
Dictionary<string, int> studentNames = new Dictionary<string, int>();
studentNames.Add("a", a);//1
studentNames.Add("b", b);
studentNames.Add("c", c);
studentNames.Add("d", d);
studentNames.Add("e", ee);
studentNames.Add("f", ff);
studentNames.Add("g", gg);
studentNames.Add("h", hh);
studentNames.Add("i", ii);//9
studentNames.Add("j", j);
studentNames.Add("k", k);
studentNames.Add("l", l);
studentNames.Add("m", m);
studentNames.Add("n", n);
studentNames.Add("o", o);
studentNames.Add("p", p);
studentNames.Add("q", q);
studentNames.Add("r", r);
studentNames.Add("s", s);
studentNames.Add("t", t);//20
studentNames.Add("u", u);
studentNames.Add("v", v);
studentNames.Add("w", w);
studentNames.Add("x", x);
studentNames.Add("y", y);
studentNames.Add("z", z);
studentNames.Add("AA", AA);
studentNames.Add("BB", BB);//28
}
public int getValue()
{
List<int> usedNumbers = new List<int>();
Random rnd = new Random();
int tempValue = rnd.Next(0, 27);
if (usedNumbers.Contains(tempValue))
{
// Go back to getValue() to have the tempValue get a new value
}
else
{
usedNumbers.Add(tempValue);
return tempValue;
}
}
}