I need to output the value of d using the same Console.WriteLine. But i am only getting Result not the value of d in output. In what way i can achieve this?
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int a;
int b;
Console.WriteLine("Please Enter the first Digit");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please Enter the Second Digit");
b = Convert.ToInt32(Console.ReadLine());
int d = a + b;
Console.WriteLine("Result",(d));
}
}
}
Use:
You are using this overload.
UPDATE
If you look at the link above, you can read how it works. In short, first you specify the formatting, where {0} references the first value of the param object-array, {1} references the second value of the param object-array, etc. After the format, you give the objects to use.
So in your case, you need a single value, which means two arguments, a format, and a value. Hence “Result {0}” with d, which will become (when for example d=10) “Result 10”.
Note: also removed the unnecessary parenthesis.