Sudantha Sudantha - 4 months ago 21
ASP.NET (C#) Question

Return a null from Function which returns a DateTime

public static DateTime ResolveDate()
{
return null;
}


Im required to return a
null
value from a function which returns a
DateTime
Type .. My Main Objective is to NOT to use MinValue or return a
new Datetime();
[Which Returns a Default Date] and Frontend display the Date as a Empty Value (Blank) ->
""

Answer
public static DateTime? ResolveDate() 
{ 
    if ( someconditon = true )
    {
        return DateTime.Now
    }
    else
    {
        return null; 
    } 
}

An alternative is to use something like TryParse is working

Public static bool TryResolve (out Resolvedate)
{
    if ( someconditon = true ) 
    { 
        Resolvedate = DateTime.Now 
        return true;
    } 
    else 
    {
        return false;  
    }  
}