I have an array of objects:
object[] myArray
This array can contain int, string, DateTime data types and so on.
Now I am trying to check if an object within myArray is of type DateTime and not null so I perform below ternary:
string strDate = myArray[pos] != null && myArray[pos].GetType() is typeof(DateTime) ? Convert.ToDateTime(myArray[pos]).ToString("dd/MM/yyyy") : string.Empty;
But I get below error starting from typeof(DateTime):
Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement