IsNull extension method for C# and VB.NET

You can use the IsNull Extension method by using the snippet below.

Sample C#

public static bool IsNull(this object source)
{
     return source == null;
}

Sample VB.NET

<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsNull(source As Object) As Boolean
	Return source Is Nothing
End Function

As always, this extension method has been added to the Github Fesslersoft.Extensions Repository

How to check if a number is a power of 2 in C# and VB.NET

To check if a number is a power of 2 in C# and VB.NET you can use the following extension method.

Sample C#

public static bool IsPowerOfTwo(this ulong input)
{
    return (input != 0) && ((input & (input - 1)) == 0);
}

Sample VB.NET

<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsPowerOfTwo(input As ULong) As Boolean
	Return (input <> 0) AndAlso ((input And (input - 1)) = 0)
End Function

As always, the extension method was added to out Fesslersoft.Extensions library @Github

IsLargerThan extension method for C# and VB.NET

If you need a IsLargerThan extension method you can use the follwing snippet.

Sample C#

public static bool IsLargerThan(this byte input, byte numberToCheck)
{
	return input > numberToCheck;
}

public static bool IsLargerThan(this sbyte input, sbyte numberToCheck)
{
	return input > numberToCheck;
}

public static bool IsLargerThan(this short input, short numberToCheck)
{
	return input > numberToCheck;
}
public static bool IsLargerThan(this ushort input, ushort numberToCheck)
{
	return input > numberToCheck;
}
public static bool IsLargerThan(this int input, int numberToCheck)
{
	return input > numberToCheck;
}

public static bool IsLargerThan(this uint input, uint numberToCheck)
{
	return input > numberToCheck;
}

public static bool IsLargerThan(this long input, long numberToCheck)
{
	return input > numberToCheck;
}
public static bool IsLargerThan(this ulong input, ulong numberToCheck)
{
	return input > numberToCheck;
}

public static bool IsLargerThan(this float input, float numberToCheck)
{
	return input > numberToCheck;
}

public static bool IsLargerThan(this double input, double numberToCheck)
{
	return input > numberToCheck;
}

public static bool IsLargerThan(this decimal input, decimal numberToCheck)
{
	return input > numberToCheck;
}

>h2>Sample VB.NET>/h2>

<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsLargerThan(input As Byte, numberToCheck As Byte) As Boolean
	Return input > numberToCheck
End Function

<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsLargerThan(input As SByte, numberToCheck As SByte) As Boolean
	Return input > numberToCheck
End Function

<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsLargerThan(input As Short, numberToCheck As Short) As Boolean
	Return input > numberToCheck
End Function
<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsLargerThan(input As UShort, numberToCheck As UShort) As Boolean
	Return input > numberToCheck
End Function
<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsLargerThan(input As Integer, numberToCheck As Integer) As Boolean
	Return input > numberToCheck
End Function

<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsLargerThan(input As UInteger, numberToCheck As UInteger) As Boolean
	Return input > numberToCheck
End Function

<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsLargerThan(input As Long, numberToCheck As Long) As Boolean
	Return input > numberToCheck
End Function
<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsLargerThan(input As ULong, numberToCheck As ULong) As Boolean
	Return input > numberToCheck
End Function

<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsLargerThan(input As Single, numberToCheck As Single) As Boolean
	Return input > numberToCheck
End Function

<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsLargerThan(input As Double, numberToCheck As Double) As Boolean
	Return input > numberToCheck
End Function

<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsLargerThan(input As Decimal, numberToCheck As Decimal) As Boolean
	Return input > numberToCheck
End Function

How to check if a string is Null or Empty or Whitespace in C# or VB.NET

To check if a string is Null or Empty or Whitespace in C# or VB.NET you can use the following Extension Method.

Sample C#

public static bool IsNotNullOrEmptyOrWhiteSpace(this string input)
{
	return !input.IsNullOrEmptyOrWhiteSpace();
}

public static bool IsNullOrEmptyOrWhiteSpace(this string input)
{
	return string.IsNullOrEmpty(input) || input.Trim() == string.Empty;
}

Sample VB.NET

<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsNotNullOrEmptyOrWhiteSpace(input As String) As Boolean
	Return Not input.IsNullOrEmptyOrWhiteSpace()
End Function

<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsNullOrEmptyOrWhiteSpace(input As String) As Boolean
	Return String.IsNullOrEmpty(input) OrElse input.Trim() = String.Empty
End Function