How to get multiple inputs from user in a single line in C#

Updated on January 20, 2019 in [A] C# .Net
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on January 20, 2019

Hi

In C++ We can take multiple inputs from a user in a single line. So My Question is how can we take multiple inputs from the user in C# without using loop.

Thanks in Advance

  • Liked by
  • Visual
Reply
0 on January 20, 2019

split up your input by the spaces, store them into an array and handle individually.
For example:

// user text is "Take sword"
String[] userInput = text.Split(' ');

userInput[0] is “Take” and userInput[1] is “sword”

https://docs.microsoft.com/en-us/dotnet/csharp/how-to/parse-strings-using-split

 

  • Liked by
Reply
Cancel