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

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -