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

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.
 
K

Kevin Spencer

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
 
J

Johan

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top