c# - Use looped array to take in string inputs -


i looking find way take assign value of user inputs variables have, use loop take entry , position on screen. there way this?

below non-working code should provide idea of trying achieve.

public void studentdetailinput()     {         const int startpoint = 2;         string[] takeinput = new string[] {firstname, surname, middlename, studentid, subject, addressline1, addressline2, town, postcode, telephone, email };          (int x = 0; x < takeinput.length; x++)         {             console.setcursorposition(30, startpoint + x);             [x] = console.readline();         }     } 

you might want use dictionary:

private dictionary<string, string> _answers = new dictionary<string, string>();  public void studentdetailinput() {     string[] takeinput = new string[] {          "firstname",          "surname",         "middlename",         "studentid",         "subject",         "addressline1",          "addressline2",         "town",          "postcode",          "telephone",         "email"      };      _answers.clear();     (int x = 0; x < takeinput.length; x++)     {         console.write(takeinput[x] + ": ");         var answer = console.readline();         _answers.add(takeinput[x], answer);      } } 

so can display answers this:

for(var = 0; < _answers.count; i++) {     console.writeline("{0}: {1}", _answers.keys[i], _answers.values[i]); } 

if concern not want use many lines on console keep track of length of answers , try put cursor right behind answers far. problem you'll need take screen's width (which can adjusted user) account calculate correct line , position.

another issue construction users expect cursor go 1 line down (that enter does) user experience might suffer.

an alternative clear screen after each input, display answers far starting @ line 2 of console , positioning next question on line one:

for (int x = 0; x < takeinput.length; x++) {     console.clear();     for(y = 0; y < x; y++)     {         console.setcursorposition(0, y + 1);         console.writeline("{0}: {1}", _answers.keys[y], _answers.values[y]);     }     console.setcursorposition(0, 0);     console.write(takeinput[x] + ": ");     var answer = console.readline();     _answers.add(takeinput[x], answer); } 

this might go horribly wrong when number of questions more number of lines on console.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -