Hi,
I wanted to know if there is a better way to write the code for this method that I am using in my project.
public Coordinates GetNodeCoordinates(int number)
{
Coordinates coords = new Coordinates();
foreach(Node node in nodes)
{
if (node.Number == number)
{
coords = node.Coordinates;
return coords;
}
}
return coords;
}
It basically goes through a 2 dimensional array and if the value in the array object matches the other value it returns a coordinate object. The way I have made my program is that it is impossible for the value being searched for to not be in the array. I do not want to have the second return statement after the foreach loop because I know it will never be called. But the compiler complains if I remove it. Can somebody tell me if there is any way to write this method so I don't have to write the second return statement.