开发者

Operator '&&' cannot be applied to operands of type 'bool' [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the开发者_JAVA百科 help center. Closed 11 years ago.
if ((!s.IsValidCashFlow) && (s.Cash.InvalidCashFlowReason == InvalidCashFlowReason.IAmAPoorMF))

I guess you can't do this in C#? isValidCashFlow is a bool property

updated:

the error is actually in my .ascx, wrong place:

<div id="Div1" " runat="server" visible="<%#(!Container.DataItem.IsValidCashFlow && (Product)Container.DataItem.Product)InvalidCashFlowReason == InvalidCashFlowReason.IAmAPoorMF %>"> 

Resolved: I added the extra () as the compiler was getting confused:

<div id="Div1" " runat="server" visible="<%#(!Container.DataItem.IsValidCashFlow && ((Product)Container.DataItem.Product)InvalidCashFlowReason == InvalidCashFlowReason.IAmAPoorMF) %>">


You can apply && between bools. Everything in a conditional evaluates to bools, so if && ever works, it's being applied to multiple bool values.


You can absolutely do this, but there must be something else going on. Can you present a more complete code sample, and print the compiler error?


Cannot reproduce:

var t = new { InvalidCashFlowReason = InvalidCashFlowReason.IAmAPoorMF};
var s = new {IsValidCashFlow = true, Cash = t};
if ((!s.IsValidCashFlow) &&
    (s.Cash.InvalidCashFlowReason == InvalidCashFlowReason.IAmAPoorMF))
{}

What exact compiler version are you using? Is something else amiss?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜