ExtensionMethod.NET Home of 876 C#, Visual Basic, F# and Javascript extension methods


Determines how many numbers compose the integer if it was represented as a string.


public static int Length(this int i)
    if (i <= 0) throw new ArgumentOutOfRangeException();

    return (int)Math.Floor(Math.Log10(i)) + 1;


int ir = 84372;

Console.WriteLine(ir.Length()); //will write 5

Author: Phil Campbell

Submitted on: 24 mrt. 2010

Language: C#

Type: System.Int32

Views: 5049