Socket.ReceiveFrom(): why is EndPoint a ref parameter?

  • Thread starter Thread starter Johan
  • Start date Start date
J

Johan

Why is the parameter remoteEP of the function Socket.ReceiveFrom() a
ref parameter and not an out parameter?

http://msdn2.microsoft.com/en-us/library/wdfskwcy.aspx

public int ReceiveFrom (
byte[] buffer,
ref EndPoint remoteEP
)

I think it should be a out parameter, because the function doesn't use
the value. It only puts information about the remote end in this
class. In most examples the EndPoint is initialised like this:
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);

But this doesn't do anything (right?). I think it is only used to keep
the compiler happy.
 
An out parameter does not have to exist. A ref parameter does have to exist.
And a receiver must exist in order to receive data from anything. So, making
it an out parameter doesn't make sense.

--
HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
I should have mentioned that I mean the function
UdpClient.ReceiveFrom().

A ref parameter has to be initialized before passing it to a function.
But this initialization is nonsense because the ReceiveFrom() function
does not use these values.
So my question remains: Why is it a ref parameter and not an out
parameter?



An out parameter does not have to exist. A ref parameter does have to exist.
And a receiver must exist in order to receive data from anything. So, making
it an out parameter doesn't make sense.

--
HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:http://www.miradyne.net


Why is the parameter remoteEP of the function Socket.ReceiveFrom() a
ref parameter and not an out parameter?

public int ReceiveFrom (
byte[] buffer,
ref EndPoint remoteEP
)
I think it should be a out parameter, because the function doesn't use
the value. It only puts information about the remote end in this
class. In most examples the EndPoint is initialised like this:
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
But this doesn't do anything (right?). I think it is only used to keep
the compiler happy.
 
Back
Top