c# - Refactor an ugly loop into LINQ -


I have the following code peace, which is the 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; }}

I am looking for signals on how to improve it, probably using LINQ.

There is an IETator version:

  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; }}   

Only LINQ will make this code less readable in that particular case.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -