> "Nguyen Thanh Danh" wrote:
i want to inherit class Socket in System.Nets.Sockets,
but when i use this code:
public class NewSocket : System.Net.Sockets.Socket{
public NewSocket(){
}
}
and when i build it warning : No overload for method
'Socket' takes '0' arguments. Anyone please help me.
Can U show me the way to inherit Socket class because
request of my project is rewrite Socket
with some new function. Thanks alot!
To achieve what you want, you have to provide more information, such as what
the Socket is supposed to be used for.
When you inherit from Socket, you have to call the constructor of the
super-class with valid arguments. There is a large list of constants you can
use there, but which ones to use is depending on what you'll be using it
for.
One simple example that compiles without warnings:
using System.Net.Sockets;
public class MySocket : Socket
{
public MySocket( ) :
base(
AddressFamily.InterNetwork,
SocketType.Unknown,
ProtocolType.Tcp)
{
}
}
I suggest you look into the different constants of AddressFamily, SocketType
and ProtocolType, to decide which ones are best suited for your project.
If it's just added functionality you're after, you don't have to use the
*empty* constructor at all. To create an instance of Socket you have to
provide three arguments, whick you can do with the sub-class as well. This
example will also work:
using System.Net.Sockets;
public class MySocket : Socket
{
public MySocket(
AddressFamily a,
SocketType s,
ProtocolType p ) : base(a, s, p)
{
}
}
// Bjorn A