await webSocket.CloseAsync(WebSocketCloseStatus.InternalServerError, "Server error", CancellationToken.None);
var result = await webSocket.ReceiveAsync(buffer, CancellationToken.None); if (result.MessageType == WebSocketMessageType.Close) { var closeStatus = (WebSocketCloseStatus)result.CloseStatus; // Do something with the close status code }In this example, we check if the received WebSocket message is a close frame and then cast the close status code to a WebSocketCloseStatus enum. Package library: The WebSocketCloseStatus enum is part of the System.Net.WebSockets namespace, which is included in the System.Net.WebSockets.Client package.