3
Answers

why need implicit operator while creating child class

sachin dimbre

sachin dimbre

11y
1.2k
1
Hello,

Why we need implicit operator while creating child class in c sharp?

I am creating wrapper classes(c#) for the classes supported by one Automation tool.
ex.  something like "public class MyClass : ToolClass" and so on for some other classes also


Concern:
1) Why do I need to add two implicit cast operators and a constructor to the newly created class(MyClass).

                           public static implicit operator MyClass(Element element);
                           public static implicit operator MyClass(string path);

2) As MyClass is child of ToolClass it should call this implicitly (as ToolClass is already doing this.)

Thanks in advance...
Answers (3)