methods - How to take input from user in C#? -
i have following program.
using system; public class myeventhandler { private int x; private int y; public myeventhandler(int a, int b) { x = a; y = b; } public myeventhandler() { } public int add() { return x + y; } public int sub() { return x - y; } } public class test { public static void main() { int a, b; console.writeline("enter first number"); = convert.toint32(console.readline()); console.writeline("enetr second no"); b = convert.toint32(console.readline()); myeventhandler mh = new myeventhandler(a,b); int z = mh.add(); console.writeline("you enetered {0} , {1} sum {}", a, b,z); console.readkey(); //console.writeline("the sum of {0} , {1} {2}", a, b, mh.add()); //console.readkey(); } }
when run program, stops working after taking both input. cannot find what's wrong here.
as shown in code believe value taken user first converted int , saved variable a.
if what's problem?
you getting formatexception
because "{}" not recognized format. change line of code to...
console.writeline("you enetered {0} , {1} sum {2}", a, b,z);
and should fine
Comments
Post a Comment