dimanche 16 avril 2017

getting random line from textfile on keypress [C#]

I'm trying to get a random line from a text file every time I press F9.

What I'm using is:

static class Randomyze
        {
            public static string[] allLinks = File.ReadAllLines(@"links.txt");
            public static Random randomLink = new Random();
            public static int setLink = randomLink.Next(0, allLinks.Length - 1);
            public static String getLink = allLinks[setLink];
        }

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.F9)
 { 
            MessageBox.Show(Randomyze.getLink); 
}
            return true;
else
{
            return base.ProcessCmdKey(ref msg, keyData);
}

But I keep getting the same return of line when I press F9.

What am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire