In high school I've studied basic C/C++ (it basically was C with cin and cout - those were the only C++ things, so I'd rather say I've been studying C in my high school time)
Now that I'm in college, I have to transition to C#.
I'm currently trying to make this C program in C#.
int main()
{
int array[100];
for (int i = 0; i < 5; i++)
{
cin >> array[i];
}
for (int i = 0; i < 5; i++)
{
cout << array[i] << " ";
}
}
Here is how I tried to write it using C#:
using System;
using System.Linq;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
int[] array = new int[100];
for (int i = 0; i < 3; i++)
{
array[i] = Convert.ToInt32(Console.ReadLine());
}
for (int i = 0; i < 3; i++)
{
Console.WriteLine(array[i]);
}
}
}
}
and it's kind of similar but it has a problem that I don't know how to fix.
In C, building that program, I could've entered data like this:
In C#, I can't, because I'm getting an exception:
I kind of understand what's happening - in C#, using Console.ReadLine() reads that line as a string, and then it tries to convert into an integer.
That does fail because of the spaces between the digits - "1 2 3".
But in C this works, because cin works differently, I guess. (I don't know how though and at this point I don't care anymore, I probably won't be using C/C++ anymore).
How can I replicate this behavior of the C program in the C# program so I can enter data as I did in the pic?