This article shares with you the method of C# cast conversion and attempting conversion for your reference. The specific content is as follows
Convert the Object type of String[] to String[] type:
public string ObjectToString(object ob) { string str = ; if (ob is string[]) { string[] strList = (string[])ob; } return str; }
Use is to determine whether ob is of type string[].
Convert string type to DateTime type:
public DateTime StringToDateTime(string str) { DateTime dateTime = new DateTime(); if ((str, out dateTime)) { return dateTime; } return dateTime; }
Notice:
When using (); to make conversion judgment, if true is returned, the cast result will be passed into DateTime; if false is returned, the cast cannot be cast.
You can also use (); to perform cast conversion, but it is impossible to determine whether cast conversion can be performed. An exception will be reported when cast conversion cannot be performed.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.