All C# extension methods for type int32
-
IsPrime
Returns true when a integer is a prime.
-
TryParse
This method takes away the need for writing two lines for TryParse and gives users an option of returning a default number.
-
int.IsNumber()
Checks if an integer is a number
-
KB,MB,GB,TB
Simplest way to get a number of bytes at different measures. KB, MB, GB or TB,
-
ToInteger
Convert datatable field to int32
-
IsInRange
Finds if the int is the specified range
-
WordCount
Count all words in a given string. Excludes whitespaces, tabs and line breaks.
-
Map
Re-maps a number from one range to another. That is, a value of fromLow would get mapped to toLow, a value of fromHigh to toHigh, values in-between to values in-between, etc.
(like Arduino function map)
Parameters
value: the number to map.
fromLow: the lower bound of the value’s current range.
fromHigh: the upper bound of the value’s current range.
toLow: the lower bound of the value’s target range.
toHigh: the upper bound of the value’s target range.
-
LCM
Uses the Euclidean Algorithm to determine the Least Common Multiplier for an array of integers
-
Squared
Returns the squared value
-
IsOdd
Checks whether a number is odd
-
To
Creates a range of integers as an IEnumerable
. -
IntToGuid
Converts an integer to a Guid. This could be used within a unit test to mock objects.
-
Times
Repeats an action a number of times.
-
ToArray
Returns an array of int containing all caracters that compose the number.
-
SecondsToString
Converts the number of seconds to a string displaying hours and minutes
-
KB
Simplest way to get a number of kilobytes.
-
TimesSelector
Inspired from ye good old ruby on rails, provides you with new DateTime instances based on an integer you provide. Look at realfiction.net -> extension methods for more detail
-
MB
Simplest way to get a number of megabytes.
-
Length
Determines how many numbers compose the integer if it was represented as a string.
-
MultiplyBy
A simple multiplication extension. Backing idea is to overcome the ridiculous flaw in the Int32 value type when a regular multiplication overflows the Int32 value range.
Along these lines it would also be possible to gracefully return larger values as e.g. longs, or as BigInt (when the BCL team gets around to implementing it ;-). But the example here sticks to the bounds of the Int32 range.
-
In
Returns true when a number is included in the specified collection.
-
IsEven
Checks whether a number is even
-
TimesOrUntil
Attempts to retrieve a valid a result from your function one or more times with an optional 'in between' step (i.e. delay).
Replaces a common code pattern with a more readable, shared pattern.
-
ExcelColumnName
Returns the excel column name from a column index
-
Intuitive date creation
Allows you to create date very easily, like 19.June(1970)
-
IntegerToTimeSpan
Converts an integer to a timespan
-
AddOrdinal
Add an ordinal to a number,
-
AsSequenceTo
Creates a numeric list of integers starting at the current instance and ending at the maximum value.