'How to interpolate a value in ForEach() C#

I have a foreach loop that I need to interpolate and add values to a list. I have model that I need to select from.

here are the POCOs I use for the selection.

public class Data
    {
        
        public int UnixTime { get; set; }
        public DateTime UnixDateTime { get; set; }
        public float TestTime { get; set; }
        public float AirTemp { get; set; }
        public float RH { get; set; }
        public float SurfaceTemp { get; set; }
        public double LowFreq { get; set; }

    }

EDIT:

    var userType = "RH"; // Statically typed here, but it gets passed in as a parameter on a method not included. 
   

    foreach (var item in GetListOfSensorData)
    {
     Two separate lists I add to. 
      unixTimeList.Add(item.UnixTime);
       
      //I could hard code item.TestTime .. AirTemp .. etc
      // I didn't want to do that. I want to concatenate or 
      //  interpolate that string onto item 
       
      selectedDataList.Add(item. "interpolate here"); 
    }

A user makes this selection. I didn't want to make a bunch of if conditions so I thought interpolate would work.

What I have tried: Multiple ways to concatenate and interpolate the value. I don't get the values back when using interpolation.

What I'm hoping for: When I hard code the value selectedDataList.Add(item.RH); I get the values I'm looking for. I don't get the results when I interpolate. I get a concatenated string basically.

Is there a way to interpolate the item I'm looking for in the foreach loop?

Screen shot of what I'm seeing from the interpolation.

enter image description here

Compared to when I hard code the value

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source