读书人

一个关于Socket的有关问题!马上给分

发布时间: 2011-12-28 22:45:21 作者: rapoo

一个关于Socket的问题!马上给分,马上结贴
请问currentSocket在什么情况下为null,什么情况下不为null呢?谢谢!

private Socket currentSocket;
if(currentSocket==null)
{

}

[解决办法]
没new就是null
new了就不是null
这个和是不是处女一个道理
[解决办法]
如果currentSocket 没有指向某个实例,就是null

相反则非空。

一般在socket推出时可以这么判断

if(currentSocket != null)
{
currentSocket.Shutdown(SocketShutdown.Both);
currentSocket.Close();
}

读书人网 >C#

热点推荐