You need to string.Split() the input like so:
var inp = Console.ReadLine();
var split = inp.Split(' ');
if (split.Length == 2
&& int.TryParse(split[0], out var a) // assumes C#7 feature of inline var declaration
&& int.TryParse(split[1], out var b) // for out parameters, else declare ints earlyer
)
{
// do something with a and b which are ints....
}
else
{
// either not enough or too many or non-int input by the usere. handle it.
}
Just for giggles sake: if you want to be really lenient with inputs and like one-liners (I dont, dont do such things in production code ;o) you could do this :
// needs: using System.Linq; in addition to using System;
var any = false;
var sum = 0l;
Console.WriteLine( // write something
Console.ReadLine() // what you read via console input
.Split(' ') // thats being split by' '
.Where(part => int.TryParse(part, out var _)) // only use things parsable as int
.Aggregate("", (acc, part) => // for each thing you got, create a string starting
{ // with an empty string
any = true; // remeber we had some valid input
if (acc.Length > 0) // already something in string?
acc += " + "; // add " + " to it
acc += part; // add the string that is parsable to int to result
sum += int.Parse(part); // it is parseable, so parse and add up
return acc; // return what we have agg'ed so far to next cycle
}) + (any ? $" = {sum}" : "No valid numbers in input."));
// check if we got any, if so add sum to the console output, else the agg is ""
// and we output our "error" message
Which will use every "correct" integer number in the input and print out the complete addition of correct integers if they fit into a long
. It will ignore any number that is not parsable as integer, so in.MaxValue + 1
wont be added (too big), decimals wont be added. If no valid input is detected you get a message for that:
Input: hdfh 5 2h 6 7 -3 -9 222222222222222222222222222222222 76.43 2 3 4 -1000
Output: 5 + 6 + 7 + -3 + -9 + 2 + 3 + 4 + -1000 = -985