BeneathTheStars
Sorceror
Repeats in Arrays
I have a problem with an array, and it seems like an easy solution that i have seen before..but cannot find where...
I have a array filled with...animals, lots of different types. I want the array to count how many of each animal there are in the array(done that)..without counting the same animal again later on...
It should find a 'animal', count how many there are, and move on. Then disregard it the next time it runs into it.
I cannot remove the 'animal' for it would change the size of the array, and replacing the animal did nothing...
('animals' are an example)
I have a problem with an array, and it seems like an easy solution that i have seen before..but cannot find where...
I have a array filled with...animals, lots of different types. I want the array to count how many of each animal there are in the array(done that)..without counting the same animal again later on...
Code:
private void CountTypes()
{
foreach (string s in m_types)
{
int count = 0;
for (int i = 0; i < m_types.Count; i++)
{
if (s == m_types[i].ToString())
{
if (count == 0)
m_filetypes.Add(m_types[i].ToString());
count++;
}
}
m_filecount.Add(count);
}
for (int i = 0; i < m_filetypes.Count; i++)
{
SetText4(""+m_filetypes[i]+" "+m_filecount[i]);
}
}
It should find a 'animal', count how many there are, and move on. Then disregard it the next time it runs into it.
I cannot remove the 'animal' for it would change the size of the array, and replacing the animal did nothing...
('animals' are an example)