Avatar ·

How to add values to an array in C# after it's created?

Hello everyone! I just started learning C# and encountered a problem that seems very strange to me. In other languages, like JavaScript or Python, I can easily create an empty array and then add elements to it using the push() or append() method. But in C# I can't figure out how to do this. Here's an example of my code: ```csharp int[] numbers = new int[5]; numbers[0] = 10; numbers[1] = 20; // I can do it this way, but I need to know the size in advance! ``` But what if I don't know how many elements there will be? For example, the user enters numbers from the keyboard, and I want to save them to an array. I tried this: ```csharp int[] numbers = {}; numbers[0] = 10; // Error: IndexOutOfRangeException ``` Or this: ```csharp int[] numbers; numbers[0] = 10; // Compilation error: use of uninitialized