So I've been trying to do a program, which looked really simple at first, but I guess I must have underestimated it. The program is to receive 2 List with Console.ReadLine() and then merge them in a 3rd list, then List.Sort and print it.
using System;
using System.Collections.Generic;
using System.Linq;
namespace Array.Merge
{
class Program
{
static void Main(string[] args)
{
string input1 = Console.ReadLine();
string input2 = Console.ReadLine();
List<int> numbers1 = input1.Split(" ").Select(int.Parse).ToList();
List<int> numbers2 = input2.Split(" ").Select(int.Parse).ToList();
List<int> numbers = new List<int>();
for (int a = 0; a < numbers1.Count; a++)
{
numbers.Add(numbers1[a]);
}
for (int b = 0; b < numbers2.Count; b++)
{
numbers.Add(numbers2[b]);
}
numbers.Sort();
foreach(int number in numbers)
{
Console.Write(number + " ");
}
}
}
}
when I submit my 2 lines of input, I get the error "Input string was not in a correct format" in the console. This is the input I am using:
1 2 3 7 9
2 4 5 7 8
This is what I should be receiving:
1 2 2 3 4 5 7 7 8 9