Is it possible to instantiate a variable like following example
OwnType variable = "String";
instead of
OwnType variable = new OwnType("String");
Maybe with a index field in OwnType or something similar?
Yes, you can do it with an implicit conversion operator from string
to OwnType
. This would let you hide the call of operator new
in the operator:
public static implicit operator OwnType(string str)
{
return new OwnType(str);
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments