1
General Discussion / Re: Questions Not Worth Their Own Thread: C# Edition
« Last post by db48x on Today at 12:49:23 AM »Yes, you are correct.
Here is the relevant code:
Code: [Select]…
PossibleSystems = KnownSystems.Values.Except(CurrentSystems).OrderBy(x => Math.Pow(x.X - StartSystem.RealSystem.X, 2.0) + Math.Pow(x.Y - StartSystem.RealSystem.Y, 2.0) + Math.Pow(x.Z - StartSystem.RealSystem.Z, 2.0)).ToList();
…
The + should be -, as you stated above. Its been like this since C# launched and you are the first person to figure it out
I think correcting it is better than leaving as is, as it will be easier to understand what is happening.
Am I missing something? That looks like the right distance formula to me, with minus signs in the correct place.
As an aside, are you sure that you need to call ToList() there? OrderBy returns an IOrderedEnumerable, which you can directly enumerate over with a foreach loop. Calling ToList() will allocate a new List and copy the (sorted) elements into it. Then after the loop the List will be thrown away. Seems like wasted effort, but I have only a passing acquaintance with C# and could be wrong.