Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# get digits from int

// without LINQ (see linked source for more solutions with or w/o LINQ
public static IEnumerable<int> GetDigits(int source)
{
    int individualFactor = 0;
    int tennerFactor = Convert.ToInt32(Math.Pow(10, source.ToString().Length));
    do
    {
        source -= tennerFactor * individualFactor;
        tennerFactor /= 10;
        individualFactor = source / tennerFactor;

        yield return individualFactor;
    } while (tennerFactor > 1);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #digits #int
ADD COMMENT
Topic
Name
6+8 =