private Dictionary <string, string> DrawRandomCards() { Random r = new Random(); int[] randomNumbers = new int[10]; for (int i = 0; i < 10; i++) { int temp = r.Next(flashCardCollection.Count()); while (randomNumbers.Contains(temp)) { temp = r.Next(flashCardCollection.Count()); } randomNumbers[i] = temp; } Dictionary <string, string> randomFlashCards = new Dictionary <string, string>(); for (int i = 0; i < 10; i++) { FlashCard fs = flashCardCollection.ElementAt(randomNumbers[i]).Value; randomFlashCards.Add(fs.UrduPhrase, fs.EnglishPhrase); } return(randomFlashCards); }
private void GetFlashCardsFromFile() { TextFieldParser parser; try { parser = new TextFieldParser(Properties.Settings.Default.filePath); parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(","); parser.ReadFields(); //skips first line while (!parser.EndOfData) { string[] phrases = parser.ReadFields(); FlashCard fc = new FlashCard(); fc.UrduPhrase = phrases[0]; fc.EnglishPhrase = phrases[1]; flashCardCollection.Add(new FlashCardSet() { Key = FLASHCARDNUMBER + ++handle, Value = fc }); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }
void ad_AddFlashCardEvent(string urduWord, string englishWord) { if (flashCardCollection.Select(x => x.Value.UrduPhrase.ToLower()).Contains(urduWord)) { System.Windows.MessageBox.Show(urduWord + " already exists in flash card set!"); return; } FlashCard fc = new FlashCard(); fc.UrduPhrase = urduWord; fc.EnglishPhrase = englishWord; flashCardCollection.Add(new FlashCardSet() { Key = FLASHCARDNUMBER + ++handle, Value = fc }); ad.Close(); }