class MyClass { public string Value {get; private set;} public MyClass(string s) { this.Value = s; } public static implicit operator MyClass(string s) { return new MyClass(s); } }
Now you can:
MyClass myClass = "my string"; Console.WriteLine(myClass.Value); //prints "my string"
Note that XNamespace also supports the add statement , which takes strings as the correct parameter. This is a good API solution if you are dealing with strings. To implement this, you can also overload the addition operator:
source share