Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SocketException:ErrorCode与SocketErrorCode_C#_Sockets_Error Handling - Fatal编程技术网

C# SocketException:ErrorCode与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时都会有这种转换

ErrorCode和SocketErrorCode是否总是相同的值,但表示为不同的类型

给出了几乎相同的描述,但我没有看到任何明确的注释说明它们是相同的值

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;
    }
}