0

Can I add elements to array by Console.ReadLine??

About Arrays

8/20/2016 7:11:26 PM

Nurlan Aliyev

5 Answers

New Answer

+4

//declare array here //add elements here: for(int i = 0; i < arr.Length; i++) array[i] = Console.ReadLine();

+1

yes. pass the elements in a variable and then pass that variable into the array.do this in a for loop

0

Thank u i got it

0

keep in mind you can only add a predetermined amount of items - for i < array.length; if you wanted to maintain adding things, that's where List comes in handy.

0

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int[ ] a = new int[10]; for (int k = 0; k < 10; k++) { Console.WriteLine("enter the {0} element",k); a[k]=Convert.ToInt32(Console.ReadLine()); } for (int k = 0; k < 10; k++) { Console.WriteLine(a[k]); } } } }