Add ToBoolean()

ToBoolean() returns false if value is 0, true otherwise
This commit is contained in:
Oliver Booth 2019-11-16 01:53:16 +00:00
parent 445929e1b8
commit e537b9c727
No known key found for this signature in database
GPG Key ID: 4B0992B2602C3778
3 changed files with 54 additions and 0 deletions

View File

@ -112,5 +112,23 @@
/// otherwise.</returns>
public static bool IsPrime(this short number) =>
((long) number).IsPrime();
/// <summary>
/// Gets an boolean value that represents this integer.
/// </summary>
/// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0,
/// <see langword="true"/> otherwise.</returns>
public static bool ToBoolean(this short value) =>
value != 0;
/// <summary>
/// Gets an boolean value that represents this integer.
/// </summary>
/// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0,
/// <see langword="true"/> otherwise.</returns>
public static bool ToBoolean(this ushort value) =>
value != 0;
}
}

View File

@ -111,5 +111,23 @@
/// otherwise.</returns>
public static bool IsPrime(this int number) =>
((long)number).IsPrime();
/// <summary>
/// Gets an boolean value that represents this integer.
/// </summary>
/// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0,
/// <see langword="true"/> otherwise.</returns>
public static bool ToBoolean(this int value) =>
value != 0;
/// <summary>
/// Gets an boolean value that represents this integer.
/// </summary>
/// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0,
/// <see langword="true"/> otherwise.</returns>
public static bool ToBoolean(this uint value) =>
value != 0;
}
}

View File

@ -134,5 +134,23 @@
return true;
}
/// <summary>
/// Gets an boolean value that represents this integer.
/// </summary>
/// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0,
/// <see langword="true"/> otherwise.</returns>
public static bool ToBoolean(this long value) =>
value != 0;
/// <summary>
/// Gets an boolean value that represents this integer.
/// </summary>
/// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0,
/// <see langword="true"/> otherwise.</returns>
public static bool ToBoolean(this ulong value) =>
value != 0;
}
}