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

Please rate this snippet

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

Please rate this snippet

How to check if a character is Uppercase in C# and VB.NET

To check if a character is Uppercase in C# and VB.NET you can use the following Extension Method

Sample C#

/// <summary>
///     Checks whether the character is an uppercase Character or not
/// </summary>
/// <param name="inputChar"></param>
/// <returns>True or False depending on the character</returns>
public static bool IsUpperCase(this char inputChar)
{
	return inputChar >= 'A' && inputChar <= 'Z';
}

Sample VB.NET

''' <summary>
'''     Checks whether the character is an uppercase Character or not
''' </summary>
''' <param name="inputChar"></param>
''' <returns>True or False depending on the character</returns>
<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsUpperCase(inputChar As Char) As Boolean
	Return inputChar >= "A"C AndAlso inputChar <= "Z"C
End Function




Please rate this snippet

How to check if String is Null or Empty in XSL

To check if String is Null or Empty in XSL you can use the following snippet.

Sample XSL

<xsl:choose>
    <xsl:when test="fieldToTest != ''">
        <xsl:value-of select="Field1Value" />
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="Field2Value" />
    </xsl:otherwise>
</xsl:choose>

Please rate this snippet

What is the best datatype for money in C# and VB.NET

The best Datatype for money in C# and VB.NET is Decimal.
What is the MSDN saying about Decimal.

The Decimal value type represents decimal numbers ranging from positive 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335. The Decimal value type is appropriate for financial calculations requiring large numbers of significant integral and fractional digits and no round-off errors. The Decimal type does not eliminate the need for rounding. Rather, it minimizes errors due to rounding.

MSDN SOURCE

Please rate this snippet

How to get selected value of dropdownlist using JavaScript

To get selected value of dropdownlist using JavaScript you can use the following snippet.

Sample Javascript

var dropDown = document.getElementById("MyDropDownId");
var dropdownValue = e.options[e.selectedIndex].value; //get the value
var dropdownText = e.options[e.selectedIndex].text; //get the text

Please rate this snippet

How to check if one one string contains another string in Javascript

To check if one one string contains another string in Javascript you can use the following method.

Sample JS

if(testString.indexOf("substring") > -1){
}

Please rate this snippet

How to check if Date is Workday in C# and VB.NET

To check if Date is Workday in C# and VB.NET you can use the following snippet.

Sample C#

public static bool IsWorkDay(DateTime date, bool isWorkDaySaturday)
{
	if (date == null) {  throw new ArgumentNullException("date");}
	switch (date.DayOfWeek)
	{
		case DayOfWeek.Saturday:
			return isWorkDaySaturday;
		case DayOfWeek.Sunday:
			return false;
		default:
			return true;
	}
}

Sample VB.NET

Public Shared Function IsWorkDay(date As DateTime, isWorkDaySaturday As Boolean) As Boolean
	If date Is Nothing Then
		Throw New ArgumentNullException("date")
	End If
	Select Case date.DayOfWeek
		Case DayOfWeek.Saturday
			Return isWorkDaySaturday
		Case DayOfWeek.Sunday
			Return False
		Case Else
			Return True
	End Select
End Function

Please rate this snippet