c# - Refactor an ugly loop into LINQ -
I have the following code peace, which is the I am looking for signals on how to improve it, probably using LINQ. There is an IETator version: Only LINQ will make this code less readable in that particular case. int factor for prime numbers:
Private Stable IEnumerable & lt; Int & gt; Factor (int input) {IList & lt; Int & gt; Results = New list & lt; Int & gt; (); While (true) {var theSmallestDivisor = GetTheSmallestDivisor (input); If (largest divisor == 0) {Results. Add (input); Return result; } result. Add (biggest divisor); Input = input / smallest divider; }}
Private static IEnumerable & lt ; Int & gt; Factor (int input) {while (true) {var theSmallestDivisor = GetTheSmallestDivisor (input); If (largest divisor == 0) {yield returns input; Break the yield; } Yield back to the largest divider; Input = input / smallest divider; }}
Comments
Post a Comment