How to use an if-else statement in an array list? C# -
code:
arraylist myname = new arraylist() { "xx", "y", "z" }; random rnd = new random(); int r = rnd.next(myname.count); console.writeline(myname[r]); string x = console.readline(); if(x == "xx") { console.writeline("welcome xx"); } else if () {}.... console.readline();
i trying generate random strings array list doing successfully. want display message when each string appears , used if-else
statement this. however, if-else
statement not working. point out error in code?
arraylist myname = new arraylist() { "xx", "y", "z" }; random rnd = new random(); int r = rnd.next(myname.count); console.writeline(myname[r]); if (myname[r].equals("xx")) { console.writeline("welcome xx"); } else if (myname[r].equals("y")) { console.writeline("welcome y"); } else if (myname[r].equals("z")) { console.writeline("welcome z"); }
Comments
Post a Comment