What is the point of Convert.ToDateTime(bool)?

后端 未结 3 876
时光取名叫无心
时光取名叫无心 2020-12-20 11:42

I was doing some type conversion routines last night for a system I am working on. One of the conversions involves turning string values into their DateTime equivalents.

3条回答
  •  长情又很酷
    2020-12-20 11:52

    It makes sense because ToDateTime is part of the IConvertible interface implemented by bool. If you look in reflector you will see that it throws an InvalidCastException.

    Update (from Convert):

    public static DateTime ToDateTime(bool value)
    {
        return ((IConvertible) value).ToDateTime(null);
    }
    

提交回复
热议问题