Problem
Check collection contains the same number multiple times.
If it does contain the same numbers more than once, then I want to keep the first number and give a new value to the rest of the numbers, which are the same as the first one.
list newFitnessList
does contain These numbers:
0. 4054.230995 --> after code= 4054.230995
1. 4041.416004 --> after code= 4041.416004
2. 3926.227397 --> after code= 3926.227397
3. 4722.250903 --> after code= 4722.250903
4. 4722.250903 --> after code= 0
5. 4226.636776 --> after code= 4226.636776
6. 4061.499026 --> after code= 4061.499026
7. 3876.278254 --> after code= 3876.278254
8. 4041.416004 --> after code= 0
9. 4779.468077 --> after code= 4779.468077
10. 4226.636776 --> after code= 0
11. 3876.278254 --> after code= 0
12. 4779.468077 --> after code= 0
13. 3926.227397 --> after code= 0
To achieve the solution explained above I tried the following code, but nothing is happening. The Output of the list is the same as before:
public List<double> sortDoppelganger(List<double> inputFitnessList)
{
List<double> newFitnessList = inputFitnessList.ToList();
for(int i = 0; i < newFitnessList.Count; i++)
{
double Nothing=0;
double actual = newFitnessList[i];
for(int j = newFitnessList.Count-1; j >= 0; j--)
{
double next = newFitnessList[j];
if(actual == next)
{
next = Nothing;
}
}
}
return newFitnessList;
}
I would really appreciate it if someone has any idea what's wrong with my code. And maybe it would be better not to hide, that I'm a newbie with programming.
After reading the explanations: I tried out two idea's explained. First one was the idea of @Tim Schmelter and the second idea was from @user3185569.
And here you can take a look at what i was tyring to achieve: