Skip to content

Instantly share code, notes, and snippets.

@shawnwellner
shawnwellner / IntegerEx.cs
Last active September 24, 2025 10:57
[C#] Integer Extension Methods #snippet #extensions
public static bool In(this int value, params int[] array) {
return array.Contains(value);
}
public static int Or(this int value, int defaultValue) {
return value > 0 ? value : defaultValue;
}
@shawnwellner
shawnwellner / StringEx.cs
Last active September 24, 2025 10:57
[C#] String Extension Methods #snippet #extensions
public static bool HasValue(this string value) {
return !string.IsNullOrEmpty(value);
}
public static bool IsEmpty(this string value) {
return string.IsNullOrEmpty(value);
}
public static int ToInt(this string value) {
if (value.IsEmpty()) { return -1; }