【问题标题】:Get data out of case statement C#从case语句中获取数据C#
【发布时间】:2020-08-12 10:59:53
【问题描述】:

我正在使用我们购买的热像仪的 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 有效,但我无法调用数据。

【问题讨论】:

  • 什么意思?你想得到那个创建内部案例T3DDetectionType.DEPTH_LIVENESS:的Json吗?
  • 我想得到(firstDetection as Temperature).MeasurementValueCelsius.ToString("N1")的值,不介意JSON。我只是想把这个变量的数据用在switch语句之外
  • 在 c# 中创建 json 字符串时,我会考虑序列化。构建一个对象并序列化为 json。不过,我在那里看到了一些非常奇怪的东西。你要把图片作为json发送吗?我希望有一个枚举。为什么要关心字符串格式?我希望这是接收 json 的任何人的工作。你也有不同的变量似乎很奇怪。这将是一个不同的序列化类,或者可能只是一个。

标签: c# .net wpf sdk switch-statement


【解决方案1】:

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

  • 在switch语句之前声明一个变量
string firstDetection = string.Empty;
  • 并将所需的值分配给开关盒内的该变量。
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 中获得所需的值。

【讨论】:

    猜你喜欢
    • 2015-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多