c# - Returning the value of a function with out assigning it to a variable -


so trying take list of user inputs , place them directly array. without assigning variable each input because there hundreds.

        static void writeandwait(string statement, int millisecondstowait)     {         console.writeline(statement);         thread.sleep(millisecondstowait);         return;     }     static void main(string[] args)     {         //i using arraylists because store many values needed wether 1 or 1,000,000 or more         arraylist name; //declaring name           arraylist time; //declaring time         arraylist path; //declaring path         name = new arraylist(); //name used store names of timers user inputs         time = new arraylist(); //time used store times of timers user inputs         path = new arraylist(); //path used store path line of timers user inuts;          writeandwait("hello, if want add timers need type name , press enter, how long want timer run in minutes, , add number 1-10 timers same number @ end run sycrnasly, , timers diferant nubers run async", 2000);         name.add(console.readkey().tostring());         console.writeline(name[0]);     } 

the console.writeline returns 'console.readkey().tostring())

i return key user inputs. or return value of console.readkey

not sure asking here, using struct prevent needing maintain separate arrays. if have dynamic number of arguments, can modify answer that.

public struct timerdescriptor {     public string name;     public string time;     public string path;      public static bool tryparse(string text, out timerdescriptor value)     {         //check empty text         if (string.isnullorwhitespace(text))         {             value = default(timerdescriptor);             return false;         }          //check wrong number of arguments         var split = text.split(new [] {' '}, stringsplitoptions.removeemptyentries);         if (split.length != 3)         {             value = default(timerdescriptor);             return false;         }          value = new timerdescriptor         {             name = split[0],             time = split[1],             path = split[2]         };          return true;     }      public override string tostring()     {         return name + ' ' + time + ' ' + path;     } }  static void writeandwait(string statement, int millisecondstowait) {     console.writeline(statement);     thread.sleep(millisecondstowait); } static void main(string[] args) {     //i using arraylists because store many values needed wether 1 or 1,000,000 or more     var timerdescriptors = new list<timerdescriptor>();      writeandwait("hello, if want add timers need type name , press enter, how long want timer run in minutes, , add number 1-10 timers same number @ end run sycrnasly, , timers diferant nubers run async", 2000);      var line = console.readline();     timerdescriptor descriptor;     if (timerdescriptor.tryparse(line, out descriptor))     {         timerdescriptors.add(descriptor);         console.writeline(descriptor);     }     else console.writeline("syntax error: wrong number of arguments.  syntax is: {name} {time} {path} without curly braces."); } 

Comments