[英]C# No Overload for method 'ToString' takes 1 argument
this is where is my error: 这是我的错误所在:
foreach (var donneesDump in don)
{
if (cap.Any(c => c.PMRQTOTM == donneesDump.PMRQTOTM))
{
if(!cap.Any(d => d.Libelle_TOT == donneesDump.Libelle_TOT))
{
cnn.Resultat.Add(new Resultat
{
NomTable = "CapitalisationActuelle",
Groupe_D_alerte = donneesDump.Groupe_Alerte,
NomChamp = "PMRQTOTM",
TOTMPMRQ = donneesDump.PMRQTOTM,
SiModifie = "Libelle TOT",
LibelléTOTAvant = cap.Any(c => c.Libelle_TOT),
LibelléTOTApres = donneesDump.Libelle_TOT,
Remarque = "Ajoute"
});
}
}
}
On line LibelléTOTAvant = cap.Any(c => c.Libelle_TOT)
I have two errors, which are finally the same: 在
LibelléTOTAvant = cap.Any(c => c.Libelle_TOT)
我有两个错误,它们最终是相同的:
Cannot convert lambda expression to delegate type 'System.Func' because some of the return types in the block are not implicitly convertible to the delegate return type.
无法将lambda表达式转换为委托类型'System.Func',因为该块中的某些返回类型不能隐式转换为委托返回类型。 AND Cannot implicitly convert type 'string' to 'bool'.
AND无法将类型'string'隐式转换为'bool'。
I have tried to do a ToString()
Method to solve the problem, like this: 我试图做一个
ToString()
方法来解决这个问题,像这样:
LibelléTOTAvant = ToString(cap.Any(c => c.Libelle_TOT)),
and then I have the error: 然后我有错误:
No Overload for method 'ToString' takes 1 argument.
方法'ToString'的任何重载都不需要1个参数。
It isn't the first time I have this kind of error, but I still don't find how solve this.. 这不是我第一次遇到这种错误,但是我仍然找不到解决方法。
Thanks in advance. 提前致谢。 Greetings.
问候。
Edit 1: 编辑1:
This is where I am. 这就是我
foreach (var donneesDUMP in don)
{
if (cap.Any(c => c.PMRQTOTM == donneesDUMP.PMRQTOTM))
{
if(!cap.Any(c => c.Libelle_TOT == donneesDUMP.Libelle_TOT))
{
cnn.Resultat.Add(new Resultat
{
NomTable = "CapitalisationActuelle",
Groupe_D_alerte = donneesDUMP.Groupe_Alerte,
NomChamp = "PMRQTOTM",
TOTMPMRQ = donneesDUMP.PMRQTOTM,
SiModifie = "Libelle TOT",
LibelléTOTAvant = cap.Select(c => c.Libelle_TOT).FirstOrDefault(),
//LibelléTOTAvant = cap.Any(c => !string.IsNullOrEmpty(c.Libelle_TOT))
//? cap.Select(x => x.Libelle_TOT).First(l => !string.IsNullOrEmpty(l))
//: " ",
LibelléTOTApres = donneesDUMP.Libelle_TOT,
Remarque = "Modifie"
});
}
}
}
Both of 两者的
LibelléTOTAvant = cap.Select(c => c.Libelle_TOT).FirstOrDefault(),
and 和
LibelléTOTAvant = cap.Any(c => !string.IsNullOrEmpty(c.Libelle_TOT))
? cap.Select(x => x.Libelle_TOT).First(l => !string.IsNullOrEmpty(l))
: " ",
works. 作品。 But each time I have one problem, probably with .First() and .FirstOrDefault().
但是每次遇到一个问题时,可能都是.First()和.FirstOrDefault()。 It always write the first Libelle_TOT, not the good one.
它总是写第一个Libelle_TOT,而不是好的。
I believe Libelle_TOT
is a string (from the Cannot implicitly convert type 'string' to 'bool'.
error message) 我相信
Libelle_TOT
是一个字符串(从Cannot implicitly convert type 'string' to 'bool'.
错误消息)
cap.Any(c => c.Libelle_TOT)
doesn't make sense in this case, as Any
should have a Func<T, bool>
as argument (something returning a bool) and you pass a Func<T, string>
. cap.Any(c => c.Libelle_TOT)
在这种情况下没有意义,因为Any
应该以Func<T, bool>
作为参数(返回布尔值),然后传递Func<T, string>
。
So you should do 所以你应该做
cap.Any(c => !string.IsNullOrEmpty(c.Libelle_TOT))
for example, or anything else needed which would return a bool. 例如,或需要返回布尔值的任何其他内容。
and if LibelléTOTAvant
is a string 如果
LibelléTOTAvant
是字符串
cap.Any(c => !string.IsNullOrEmpty(c.Libelle_TOT))
? <something which is a string>
: <something else which is a string>
EDIT 编辑
for example 例如
cap.Any(c => !string.IsNullOrEmpty(c.Libelle_TOT))
? cap.Select(x => x.Libelle_TOT).First(l => !string.IsNullOrEmpty(l))
: 'No Label'
or in this case, you could do 或者在这种情况下,您可以
cap.Select(x => x.Libelle_TOT).FirstOrDefault(l => !string.IsNullOrEmpty(l)) ?? 'No Label'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.