reading two integers in one line using C#

前端 未结 12 1721
旧巷少年郎
旧巷少年郎 2020-11-30 09:37

i know how to make a console read two integers but each integer by it self like this

int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLin         


        
12条回答
  •  盖世英雄少女心
    2020-11-30 10:12

    public static class ConsoleInput
    {
        public static IEnumerable ReadInts()
        {
            return SplitInput(Console.ReadLine()).Select(int.Parse);
        }
    
        private static IEnumerable SplitInput(string input)
        {
            return Regex.Split(input, @"\s+")
                        .Where(x => !string.IsNullOrWhiteSpace(x));
        }
    }
    

提交回复
热议问题