Click here to Skip to main content
15,896,207 members
Home / Discussions / C#
   

C#

 
AnswerRe: Handle Exception In Thread Pin
Rob Philpott28-Mar-17 0:01
Rob Philpott28-Mar-17 0:01 
GeneralRe: Handle Exception In Thread Pin
Kevin Marois28-Mar-17 5:55
professionalKevin Marois28-Mar-17 5:55 
AnswerRe: Handle Exception In Thread Pin
Nathan Minier28-Mar-17 1:35
professionalNathan Minier28-Mar-17 1:35 
AnswerRe: Handle Exception In Thread Pin
Richard Deeming28-Mar-17 1:43
mveRichard Deeming28-Mar-17 1:43 
QuestionC# Read random line Pin
Pavlex426-Mar-17 10:00
Pavlex426-Mar-17 10:00 
AnswerRe: C# Read random line Pin
Dave Kreskowiak26-Mar-17 12:52
mveDave Kreskowiak26-Mar-17 12:52 
AnswerRe: C# Read random line Pin
Garth J Lancaster26-Mar-17 13:50
professionalGarth J Lancaster26-Mar-17 13:50 
AnswerRe: C# Read random line Pin
OriginalGriff26-Mar-17 21:37
mveOriginalGriff26-Mar-17 21:37 
I would suggest that the best thing to do would be to change your file format.
If you used each line to hold a single question, together with it's possible answers, separated by '|' characters:
Planete i njihovi sateliti|Zemlja=Mesec|Mars=Fobos|Jupiter=Io|Saturn=Titan|Uran=Titania|Neptun=Triton|Pluton=Haron|Merkur=Nema satelit
Čuveni parovi iz umetnosti|Hamlet=Ofelija|Ruslan=Ljudmila|Zevs=Hera|Otelo=Dezdemona|Paris=Helena|Abelard=Eloiza|Paolo=Frančeska|Lanselot=Ginevra
...

Then the problem becomes trivial:
Use File.ReadAllLines to read the whole file into an array of strings: each element of the array is a question together with it's answers, so selecting a random question is a trivial use of the Random class.
Each question and answer can be easily split out into an array of strings using string.Split - the first element of the array is the question, the rest of them are possible answers.

But do yourself a favour: stop using Visual Studio default names for everything - you may remember that "TextBox8" is the mobile number today, but when you have to modify it in three weeks time, will you then? Use descriptive names - "tbMobileNo" for example - and your code becomes easier to read, more self documenting, easier to maintain - and surprisingly quicker to code because Intellisense can get to to "tbMobile" in three keystrokes, where "TextBox8" takes thinking about and 8 keystrokes...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

GeneralRe: C# Read random line Pin
Pavlex426-Mar-17 21:52
Pavlex426-Mar-17 21:52 
GeneralRe: C# Read random line Pin
OriginalGriff26-Mar-17 22:12
mveOriginalGriff26-Mar-17 22:12 
GeneralRe: C# Read random line Pin
Pavlex426-Mar-17 23:41
Pavlex426-Mar-17 23:41 
GeneralRe: C# Read random line Pin
Pete O'Hanlon26-Mar-17 23:45
mvePete O'Hanlon26-Mar-17 23:45 
GeneralRe: C# Read random line Pin
Pavlex427-Mar-17 0:03
Pavlex427-Mar-17 0:03 
GeneralRe: C# Read random line Pin
Pete O'Hanlon27-Mar-17 0:07
mvePete O'Hanlon27-Mar-17 0:07 
AnswerRe: C# Read random line Pin
Luc Pattyn27-Mar-17 11:15
sitebuilderLuc Pattyn27-Mar-17 11:15 
QuestionHow can I create multi-threads application in which each thread have its own WebDriver to do its tasks? Pin
khanhsk26-Mar-17 4:29
khanhsk26-Mar-17 4:29 
AnswerRe: How can I create multi-threads application in which each thread have its own WebDriver to do its tasks? Pin
Dave Kreskowiak26-Mar-17 4:49
mveDave Kreskowiak26-Mar-17 4:49 
GeneralRe: How can I create multi-threads application in which each thread have its own WebDriver to do its tasks? Pin
khanhsk26-Mar-17 23:49
khanhsk26-Mar-17 23:49 
QuestionVisual Studio 2017 problems Pin
zequion25-Mar-17 23:30
professionalzequion25-Mar-17 23:30 
AnswerRe: Visual Studio 2017 problems Pin
Michael_Davies26-Mar-17 0:11
Michael_Davies26-Mar-17 0:11 
AnswerRe: Visual Studio 2017 problems Pin
Richard MacCutchan26-Mar-17 1:37
mveRichard MacCutchan26-Mar-17 1:37 
Questionadd members to a group Pin
Member 1299778224-Mar-17 18:25
Member 1299778224-Mar-17 18:25 
AnswerRe: add members to a group Pin
Richard MacCutchan24-Mar-17 22:59
mveRichard MacCutchan24-Mar-17 22:59 
QuestionMy Downloader Tutorial Using C# and Visual Studio Pin
Member 1306314324-Mar-17 7:31
Member 1306314324-Mar-17 7:31 
AnswerRe: My Downloader Tutorial Using C# and Visual Studio Pin
Pete O'Hanlon24-Mar-17 9:17
mvePete O'Hanlon24-Mar-17 9:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.