C#
-
(C#) Generate random readable passwords
Here’s a super simple function that generates humanly readable passwords by weaving random consonants and wovels. The generated passwords are by no means secure. I did this for an application used to launch game servers and wanted to make the passwords be easy to communicate over Skype.
-
(C#) Sort lists
Lets say you have a list of person objects (List persons) You may use Sort to update the existing list. [c language=”#”] personsList.Sort((x, y) => string.Compare(x.Name, y.Name)); [/c] or OrderBy to produce a new, ordered list. [c language=”#”] var newPersonsList = persons.OrderBy(x => x.Name); [/c]
-
(C#) Confirmation when closing a form
Add an event handler for Form Closing and use this code. This is a really simple solution. [c language=”#”] private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (MessageBox.Show("Are you sure?", "Close application", MessageBoxButtons.YesNo) == DialogResult.Yes) e.Cancel = false; else e.Cancel = true; } [/c]
-
(C#) Scroll to bottom of a textbox
Short snippet: [c language=”#”] textBox.SelectionStart = textBox.TextLength; textBox.ScrollToCaret(); [/c]