I would like to know why my templist.clear()
method clears the list I added to my ManhattanDistance
Dictionary.
Any help in this regard would be much appreciated, this is part of my data mining project which I have been working on. I have to impute the missing values using k nearest neighbor approach.
public void CalculateManhattanDistance(Dictionary<int, List<string>> MissingList, Dictionary<int, List<string>> OtherList)
{
Dictionary<int,Array> MissingListNeighbours = new Dictionary<int,Array>();
Dictionary<int, List<int>> ManhattanDistanceList = new Dictionary<int,List<int>>();
List<int> tempList = new List<int>();
int total=0;
int k=0;
try
{
for (int i = 0; i < MissingList.Count(); i++)
{
for (int j = 0; j < OtherList.Count(); j++)
{
for (k = 0; k < MissingList[0].ToArray().Length; k++)
{
if (Convert.ToChar(MissingList[i][k].ToString()) == '?')
continue;
else
total += Math.Abs(Convert.ToInt32(MissingList[i][k].ToString()) - Convert.ToInt32(OtherList[j][k].ToString()));
}
tempList.Add(total);
total = 0;
}
ManhattanDistanceList.Add(i, tempList);
tempList.Clear();
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
}