Due to a bug that was fixed in C# 4, the following program prints true. (Try it in LINQPad)
void Main() { new Derived(); }
class Base {
pu
Not sure if this is what you are looking for
public static T CheckForNull(object primary, T Default)
{
try
{
if (primary != null && !(primary is DBNull))
return (T)Convert.ChangeType(primary, typeof(T));
else if (Default.GetType() == typeof(T))
return Default;
}
catch (Exception e)
{
throw new Exception("C:CFN.1 - " + e.Message + "Unexpected object type of " + primary.GetType().ToString() + " instead of " + typeof(T).ToString());
}
return default(T);
}
example: UserID = CheckForNull(Request.QueryString["UserID"], 147);