Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
C#
static void Main(string[] args)
        {
            
            int x;
            int y;
            
            Console.WriteLine("Enter the first value");
            x = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter the second value");
            y =Convert.ToInt32(Console.ReadLine());
            
           
            Console.WriteLine("The Value of added numbers are:", x+y);


what exactly is the problem in code i am not getting. But I am not able to display the result of two numbers.(result of x+y in this case).

What I have tried:

Tried solutions from different sites but nothing worked
Posted
Updated 2-Oct-19 11:05am
v3
Comments
Patrice T 2-Oct-19 16:53pm    
can you elaborate the problem.

You need to use a proper format specifier for the overload of Console.WriteLine() you are trying to use:
C#
Console.WriteLine("The Value of added numbers is: {0}", x + y);

You can also use a composite format string, if your version of c# is recent enough:
C#
Console.WriteLine($"The Value of added numbers is: {x + y}");
 
Share this answer
 
v2
Comments
Afzaal Ahmad Zeeshan 2-Oct-19 23:06pm    
5ed.
Console.WriteLine("The Value of added numbers are:", (x+y).ToString() );
 
Share this answer
 
Comments
phil.o 2-Oct-19 17:07pm    
WriteLine does not work the same way as string.Concat. You have to use a proper format string with placeholders for object parameters.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900