我有这行代码:无法确定条件表达式的类型,因为'int?'之间没有隐式转换。和“串”
Ages = m.RelatedMultipleWorks.Count == 0 ?
m.RelatedLook.Age: m.RelatedLook.Age.ToString() + " | " +
m.RelatedMultipleWorks.
Select(z => z.RelatedLook.Age.ToString()).
Aggregate((current, next) => current + " | " + next)
此行被赋予此错误:
Type of conditional expression cannot be determined because there is no implicit conversion between 'int?' and 'string'
我不明白为什么我得到这个错误。我怎样才能摆脱它?谢谢。
只需在第一个'm.RelatedLook.Age'之后添加一个'ToString'。 – juharr
你想要什么类型的“年龄”? 'm.RelatedLook.Age'是一个'int?',而'm.RelatedLook.Age.ToString()...'是一个'string'。 – haim770
在表达式的同一部分中,根据条件,您曾经分配过一个“int”和“string”,这是不可能的。你应该添加'.TosTring()'到第一个年龄段或者从第二个年龄段中删除它。取决于你的“年龄”是什么类型。 –