Convert an object type of string[] type to a string[] type:
1 Public stringObjecttostring (Objectob)2 {3 stringstr =string. Empty;4 if(ob is string[])5 {6 string[] Strlist = (string[]) ob;
7 }8 9 returnstr;Ten}
Use is to determine if OB is string[] type.
To convert a string type to a DateTime type:
1 PublicDateTime Stringtodatetime (stringstr)2 {3datetime datetime =NewDateTime ();4 if(Datetime.tryparse (str, outdateTime))5 {6 returnDateTime;7 }8 returnDateTime;9}
Attention:
Use Datetime.tryparse (); When the conversion is judged, if true, the cast result is passed into DateTime, and if False is returned, it cannot be cast.
You can also use Convert.todatetime (); Cast, but it is not possible to determine whether a cast can be made, and an exception is reported when the conversion cannot be cast.
A method for casting and trying to convert C #