Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How do I approach a question that has to do with the use of an array?
Posted
Updated 20-Oct-10 3:14am
Comments
Toli Cuturicu 20-Oct-10 8:20am    
Carefully, from the behind...
Dalek Dave 20-Oct-10 9:15am    
Minor edit for grammar.
Hiren solanki 20-Oct-10 9:33am    
simple, using 'google'
Abhinav S 20-Oct-10 13:27pm    
You might like to read a book on C# to begin with to help you on how to approach arrays.

Hi,

you work out the type of data you wish to store in it and how much of that data you need to store and you create an array that is big enough to hold it. If you don't know how big the data is, you can initialise a generic list and then use the ToArray() method on the list to convert to tyhe array of the type you want.

Eample on each type below.
C#
// arary example
int[] arr = new int[size];


C#
// Generic list
List<int> lst = new List<int>();
int[] = lst.ToArray();
</int></int>


Dave
 
Share this answer
 
v3
int[] arr = {10,20,30,40,50};
for(int i=0;i'<'arr.Length;i++)
{
Console.WriteLine(arr[i]);
}


This way you can use 5 numbers with single variable.
Otherwise you needed 5 different variables to print these 5 numbers.
 
Share this answer
 
Good article here[^] to cover basics of an array.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900