N
N
netrox2016-07-25 16:42:05
Programming
netrox, 2016-07-25 16:42:05

How to implement data entry through space in C#?

By the way, if after the beginning of the loop you need to enter the elements of the array and at the same time do not press Enter to enter a new element, but separate them with spaces. How can I do that ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Schullz, 2016-07-25
@Schullz

Read a string of type string
Split the string into parts using string.Split, the separator is a space Parse
each part into a number in some way

A
Alexander, 2016-07-25
@ded_kulibin

More or less like this:

string test = Console.Readline();
string[] temp = test.Split(new Char[] {' '});
foreach(string item in temp)
{
int num = int.Parse(item);
 //Обрабатываем каждое число отдельно.
}

M
Michael, 2016-07-25
@Madfisht3

If these are numbers, then Console.ReadKey() and when a space is encountered, get a new element. Or request all at once and string.Split().Select(p => Convert.ToInt32(p)).ToArray();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question