Doubt about vector

Asked

Viewed 35 times

0

I am trying to list the numbers that the user type but am not finding the function,someone can give me a light?

class Program
        {
            static void Main(string[] args)
            {
                int[] atividade = new int[6];
                for (int i = 1; i < 6; i++)
                {
                    Console.WriteLine("Insira o " + i + "° numero: ");
                    atividade[i] = Int32.Parse(Console.ReadLine());

1 answer

1


You can use a foreach to do this:

int[] atividade = new int[6];
for (int i = 1; i < 6; i++)
{
    Console.WriteLine("Insira o " + i + "° numero: ");
    atividade[i] = Int32.Parse(Console.ReadLine());
}
foreach(int i in atividade)
{
    Console.Write($"{i}, ");
}

It will scroll through all array values and write them to the screen.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.