Code line below prints System.Datetime
log.InfoFormat("{0}", row[2].GetType());
But row[2].GetType()
is never equals to System.DateTime
in condition below.
f.TestDate = (row[2].GetType() is System.DateTime) ? f.TestDate = (System.DateTime)row[2] : f.TestDate = DateTime.MinValue;
Why?
row[2].GetType() is System.DateTime
does not check whether row[2]
is of the type System.DateTime
but whether the Type
instance returned by GetType()
is (which it obviously isn't)
Just use
row[2] is System.DateTime
You should use:
row[2].GetType() == typeof(DateTime)
or
row[2] is DateTime
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.