I created a handler class which extends the System.Net.Sockets.Socket class. I am not familiar with casting types, inheritance or C# for that matter, so how do I cast a regular Socket to my Handler class?
I’ve tried this:
Handler handler = (Handler)socket;
But I get an InvalidCastException. Also, I do not want to extend the class by using a container class.
Thanks.
You just can’t, that’s not how inheritance works.
You can’t treat some
Socketas yourHandler. It works the other way around: you can treat yourHandleras aSocket.If you want to use your
Handler, you need to create an instance of it, by using something likenew Handler().