How to read three values on the same line? W#

-1

How can I put three values on the same row separated by space in C #? And then work with them?

Problem: link

    
asked by anonymous 11.03.2018 / 01:46

1 answer

1

You can use the String.Split to separate into spaces and then convert to decimal array.

using System;
using System.Linq;
namespace Exemplo
{
public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Múltiplos valores em uma linha");
            string inp = Console.ReadLine();
            decimal [] valores = inp.Split(' ').Select(x=> decimal.Parse(x)).ToArray();//Ou foreach se preferir.
            Console.WriteLine(string.Join(", ",valores));

        }
    }
}
    
11.03.2018 / 14:18