ErrorCode 和 SocketErrorCode 是否总是相同的值但表示为不同的类型?
SocketException class description给出了大部分相同的描述,但我没有看到任何明确说明它们具有相同的值。
SocketErrorCode 似乎更有用,因为它是一个枚举,您可以编写更漂亮的代码,例如:
if(se.SocketErrorCode == SocketError.Interrupted)
而不是:
if (se.ErrorCode != 10004)
或
if (se.ErrorCode != (int)SocketError.Interrupted)
最佳答案
是的,它们完全一样。
查看the source code :
public override int ErrorCode {
//
// the base class returns the HResult with this property
// we need the Win32 Error Code, hence the override.
//
get {
return NativeErrorCode;
}
}
public SocketError SocketErrorCode {
//
// the base class returns the HResult with this property
// we need the Win32 Error Code, hence the override.
//
get {
return (SocketError)NativeErrorCode;
}
}
关于c# - 套接字异常 : ErrorCode vs. 套接字错误代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24372866/