Answer the question
In order to leave comments, you need to log in
C# type conversion?
Hello. You need to convert the string to DateTime. Why do I need it? If a class with many properties. One such property is DateTime. I will convert the class instance to JSON manually. In JSON, the Date property (which in my class was of the DateTime type) is written by such a string received from DateTime.ToString(). After any changes with JSON data, I need to convert it back to DateTime. In principle, I can say that the body of the method will contain DateTim.Parse(str). How to do it exactly with the help of implicit and explicit?
PS: The reverse transformation of JSON -> MyType happens with new JavaScriptSerializer().Deserialize()
Answer the question
In order to leave comments, you need to log in
No way.
Operator overloading is only possible when the input or output type belongs to the class in which they are declared.
But you can make a wrapper. Here is an example about decimal. You don't need IXmlSerializer from there. You will overload operators both for a line, and for DateTime.
For DateTiee.Parse() docs and examples are here .
There will be something like
string format = "yyyyMMdd hh:mm:ss";
DateTime result = DateTime.Parse(arg, format);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question