C# help
SebiDragu (1)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
public class Program
public static void Main(string[] args)
Console.WriteLine("Hello, world!");
public static void math1()
Console.WriteLine("Enter a number: ");
int n = Int32.Parse(Console.ReadLine());
int[] numere = new int [n];

        for(int i = 0; i <= numere.Length - 1; i++)
            n = numere[i];
            Console.WriteLine("Number of elements is " + i.ToString());
            for(int j = 0; j < i; j++)
                Console.WriteLine("Elements are: " + j);

//First I wanna type "5" for example to set 5 elements and then add them and in final I want them all to show reversed.. Can you help me please?

You are viewing a single comment. View All
Answered by heyitsmarcus (287) [earned 5 cycles]
View Answer
heyitsmarcus (287)

@SebiDragu So, you can add those numbers at any specified index that is within the realm of the integer array. Let me explain: let's say I choose the number 5 in the program. That means that numere is created with 5 indices that always start at 0. You just need to specify the index to which to assign them.

So, if you want the first one to be 31 then you would put:

numere[0] = 31;
//Set the next one to be 23
numere[1] = 23;
//And so on...up until index 4 since in this example we only created 5 indices

Or you can do this when you first create the array but you'll either want to leave off the number of indices to create or add in default values to fill the array up:

//creates numere with 4 specified indices
int[] numere = new int[] { 31, 23, 44, 54 };
//or let's create numere with n=5 (but we have to specify an additional value this time to make it 5)...the number of values specified HAS to match the length of the array
//This would generally not be good since we don't know what n would be
int[] numere = new int[n] { 31, 23, 44, 54, 0 };

I hope that makes more sense.