gpt4 book ai didi

c# - 套接字异常 : ErrorCode vs. 套接字错误代码

转载 作者:行者123 更新时间:2023-11-30 16:11:26 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com