Einzelnen Beitrag anzeigen

Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#1

Typecasting in C#

  Alt 18. Jan 2009, 22:41
Hi,

In Delphi geht ja folgendes:

Delphi-Quellcode:
var x: TObject;
    y: TButton;
begin
  x := y;
end;
Das geht in C# nicht. Ich habe meine SocketEx-Klasse von Socket abgeleitet und mein Problem ist gerade, dass Socket.Accept() ein Socket zurück gibt und er mir das weder implizit noch explizit konvertieren will.

Code:
SocketEx tmp;

tmp = (SocketEx)server.Accept();
Das compiliert zwar, wirft aber eine Exception. Weiß jemand wies geht?
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat