c# - How to ask user for input -


i wondering how ask user input , check attributes of input , display output separated commas except last output. here's have far. i'm struggling asking user input, , getting rid of comma @ end of output:

using system; class testclass {  static void main(string[] args)  {   int x = convert.toint32(console.readline());  if (x < 0 || x > 25)    console.writeline("sorry, number invalid");   else    while (x <= 30)    {        if(x <= 30)        console.write(string.join(",", x));        console.write(", ");         x = x + 1;    }  } } 

it not clear trying accomplish. maybe this?

void main() {   int x;   list<int> numbers = new list<int>();    while (true)   {      console.writeline ("enter whole number between 1 , 25 or 0 end:");      string input = console.readline();       bool isinteger = int.tryparse(input, out x);       if (!isinteger || x < 0 || x > 25)      {         console.writeline (@"didn't tell ""enter whole number between 1 , 25 or 0 end? try again""");         continue;      }       if (x == 0)      {        if (numbers.count () == 0)        {         console.writeline ("pity quit game early.");        }        else        {         console.writeline (@"you have entered {0} numbers.  numbers entered were:[{1}] sum is:{2}  , average is:{3}",             numbers.count,             string.join(",", numbers.select (n => n.tostring())),             numbers.sum(),             numbers.average ());        }        break;      }      else      {        numbers.add(x);      }    } } 

Comments