C# SocketException:ErrorCode与SocketErrorCode
ErrorCode和SocketErrorCode是否总是相同的值,但表示为不同的类型 给出了几乎相同的描述,但我没有看到任何明确的注释说明它们是相同的值 SocketErrorCode似乎更有用,因为它是一个枚举,您可以生成更漂亮的代码,如:C# SocketException:ErrorCode与SocketErrorCode,c#,sockets,error-handling,C#,Sockets,Error Handling,ErrorCode和SocketErrorCode是否总是相同的值,但表示为不同的类型 给出了几乎相同的描述,但我没有看到任何明确的注释说明它们是相同的值 SocketErrorCode似乎更有用,因为它是一个枚举,您可以生成更漂亮的代码,如: if(se.SocketErrorCode == SocketError.Interrupted) 而不是: if (se.ErrorCode != 10004) 或 是的,它们完全一样 看看: 每次调用SocketErrorCode时都会有这种转换
if(se.SocketErrorCode == SocketError.Interrupted)
而不是:
if (se.ErrorCode != 10004)
或
是的,它们完全一样 看看:
每次调用SocketErrorCode时都会有这种转换,但我们希望在性能敏感的上下文中不会出现错误。
if (se.ErrorCode != (int)SocketError.Interrupted)
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;
}
}