c# - Using string constants in implicit conversion -
consider following code:
public class texttype {      public texttype(string text) {         underlyingstring = text;     }      public static implicit operator string(texttype text) {         return text.underlyingstring;     }      private string underlyingstring; }  texttype text = new texttype("something"); string str = text; // ok.   but want able following, if possible.
texttype textfromstringconstant = "someothertext";   i can't extend string class texttype implicit operator overload, there way assign literal string class (which handled method or something)?
string reference type when developed c# had use way string literal class. hope it's not hardcoded language.
public static implicit operator texttype(string text) {     return new texttype(text); }      
Comments
Post a Comment