从 case 语句 C# 中获取数据

Get data out of case statement C#

我正在使用我们购买的热像仪的 SDK。实际上我是一名 PHP Web 开发人员,现在我必须在 .Net 中编写代码

所以有一个案例,但我真的不知道如何从中获取数据。

 private void OnDetect(CallbackEventArgument callbackArgument)
 {
    var detectionResult = callbackArgument.GetDetectionResult();
    var firstDetection = detectionResult.Sequence.Items.First();

    var message = string.Empty;
    ImageArgument fullSizeImage = null;
    switch (detectionResult.Type)
    {
       case T3DDetectionType.OBSERVATION:
          message = "Track ID: " + firstDetection.TrackId;
          fullSizeImage = detectionResult.RGBImage;
          break;
       case T3DDetectionType.DEPTH_LIVENESS:
       case T3DDetectionType.THERMAL_LIVENESS:
          message = "Track ID: " + firstDetection.TrackId + " Score: " + (firstDetection as Liveness).Score.ToString("N0");
          fullSizeImage = detectionResult.FullImage;
          break;
       case T3DDetectionType.TEMPERATURE:
          message = "Temperature: " + (firstDetection as Temperature).MeasurementValueCelsius.ToString("N1") + "°C";
          fullSizeImage = detectionResult.FullImage;
          break;
    }

所以我想做的是能够在 case 之后获取 (firstDetection as Liveness).Score.ToString("N0")firstDetection.TrackId(firstDetection as Temperature).MeasurementValueCelsius.ToString("N1") + "°C" 的数据并创建一个 JSON。

创建 json 有效,但我就是无法调用数据。

如果你想从你的 switch 语句中得到一些东西,那么只需执行以下操作:

  • 在 switch 语句之前声明一个变量
string firstDetection = string.Empty;
  • 然后将您需要的值分配给 switch case 中的那个变量。
case T3DDetectionType.TEMPERATURE:
   message = "Temperature: " + (firstDetection as Temperature).MeasurementValueCelsius.ToString("N1") + "°C";
   firstDetection = (firstDetection as Temperature).MeasurementValueCelsius.ToString("N1") + "°C";
   fullSizeImage = detectionResult.FullImage;
   break;

现在,在 switch 语句之后,您将在变量 firstDetection 中获得所需的值。