C# 更改常规列表字段中的类型<&燃气轮机;

C# 更改常规列表字段中的类型<&燃气轮机;,c#,list,linq-to-entities,C#,List,Linq To Entities,我有一个调用指示符的类的列表,它需要将属性指示符值的值转换为Double 这是该类的示例 public class Indicator { public int ObjID { get; set; } public string IndicatorValue { get; set; } } 这是填充在列表中的该类的虚拟数据 IList<Indicator> IndicatorList = new List<Indicator&

我有一个调用指示符的类的列表,它需要将属性指示符值的值转换为Double

这是该类的示例

    public class Indicator
{
    public int ObjID { get; set; }

    public string IndicatorValue { get; set; }
}
这是填充在列表中的该类的虚拟数据

            IList<Indicator> IndicatorList = new List<Indicator>() {
            new Indicator(){ ObjID=1, IndicatorValue="1.8 s"},
            new Indicator(){  ObjID=2, IndicatorValue="1.5S"},
            new Indicator(){  ObjID=3, IndicatorValue="1.7 "},
            new Indicator(){  ObjID=4, IndicatorValue="1.8 S"}
        };

但是我需要在新列表中将字段指示符值转换为双精度。

您不能在运行时更改属性类型

为什么不向封装转换的
指示符
类添加一个新属性:

public class Indicator
{
    public int ObjID { get; set; }

    public string IndicatorValue { get; set; }

    public double IndicatorValueAsDouble => double.Parse(IndicatorValue.Replace("S", "").Replace(" ", "").Replace("s", ""));
}
或项目到DTO:

public class IndicatorDTO
{
     public int ObjID { get; set; }

     public double IndicatorValue { get; set; }
}

select new IndicatorDTO
{
    ObjID = fx.ObjID,
    IndicatorValue = double.Parse(fx.IndicatorValue.Replace("S", "").Replace(" ", "").Replace("s", ""));
}
public class IndicatorDTO
{
     public int ObjID { get; set; }

     public double IndicatorValue { get; set; }
}

select new IndicatorDTO
{
    ObjID = fx.ObjID,
    IndicatorValue = double.Parse(fx.IndicatorValue.Replace("S", "").Replace(" ", "").Replace("s", ""));
}