This project has moved and is read-only. For the latest updates, please go here.

System.Int32 Extension Methods

Between(int low, int high)

Summary: Returns a boolean value indicating whether the integer is between the low and high values specified. Ex: 1 is between 0 and 2, but 0 or 2 are not.
C# Example:
var i = 54;
if (i.Between(1,100))
{
    // do something
}

Days()

Summary: Returns a TimeSpan that represents the integer in days
C# Example:
var ts = 500.Days();

Hours()

Summary: Returns a TimeSpan that represents the integer in hours.
C# Example:
var ts = 3.Hours();

IsEven()

Summary: Returns a boolean indicating whether this Integer is an Even number.
C# Example:
var i = 42;
if (i.IsEven()) {
    // do something
}

IsOdd()

Summary: Returns a boolean indicating whether this Integer is an Odd number.
C# Example:
var i = 15;
if (i.IsOdd()) {
    // do something
}

Milliseconds()

Summary: Returns a TimeSpan that represents the integer in milliseconds
C# Example:
var ts = 500.Milliseconds();

Minutes()

Summary: Returns a TimeSpan that represents the integer in minutes
C# Example:
var ts = 15.Minutes();

MonthName(abbreviation = false)

Summary: Returns a string value containing the name of the specified month. Similar to the Microsoft.VisualBasic.DateAndTime.MonthName method.
abbreviation - Options. Boolean value that indicates if the month name is to be abbreviated. Default is False.
C# Example:
var january = 1.MonthName();

var feb = 2.MonthName(true);

Seconds()

Summary: Returns a TimeSpan that represents the integer in seconds
C# Example:
var ts = 30.Seconds();

Times(Action<int> action)

Summary: Executes the specified Action the specified number of times, passing in the iterator value each time.
C# Example:
10.Times((i) => {
    // do something
});

UpTo(int stopAt, Action<int> action)

Summary: Iterates from the Int through the specified stopAt and calls the specified Action for each passing in the iterator.
C# Example:
// iterate from 4 through 6
4.UpTo(6, (i) => {
    // do something
});

WeekdayName(bool abbreviation = false, DayOfWeek firstDayOfWeek = DayOfWeek.Sunday)

Summary: Returns a string containing the name of the specified weekday. Similar to the Microsoft.VisualBasic.DateAndTime.WeekdayName method.
abbreviation - Optional. Boolean value indicating if the weekday name is to be abbreviated. Default is false.
firstDayOfWeek - The numeric designation for the weekday, from 1 through 7; 1 indicates the first day of the week and 7 indicates the last day of the week
C# Example:
var monday = 2.WeekdayName();

var mon = 2.WeekdayName(true);

var friday = 1.WeekdayName(false, DayOfWeek.Friday);

Weeks()

Summary: Returns a TimeSpan that represents the integer in weeks
C# Example:
var ts = 2.Weeks();

Last edited May 4, 2012 at 3:15 PM by crpietschmann, version 8

Comments

No comments yet.