During development, while you run the application as a console application or windows form application, often the code needs to load a specific file within the same folder of the exe assembly resides. The file can be located by using the file name directory since the default location will be the exe’s [...]
Continue reading about Get Current Directory while running as WindowsService
Return null if the value type object has default value.
public static T? GetValueOrNull<t>( this T value ) where T : struct
{
if( value.Equals( default( T ) ) )
return new Nullable<t>();
else
return value;
}
// Usage
int i = default(int); //0
int? i = i.GetValueOrNull();
Console.Writeline( i.HasValue );
// output: false
Continue reading about C# Extension method, GetValueOrNull for value type object