Operator '&&' cannot be applied to operands of type 'bool' [closed]
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?
精彩评论