我试图实现多个条件运算符,但问题是,如果条件为真则总是如此。
我的要求是
如果Headername[CI]== "Yellow"
。
objnamewritten[CI]== "Banana" or objnamewritten[CI] == "Sun" or objnamewritten[CI] == "lemomn"
。
然后弹出窗口(ppup
)将会打开,如果还有其他objnamewritten[CI]
,则弹出窗口(ppup1
)将会打开。
private void common()
{
if (Headername[CI]== "Yellow")
{
if ((objnamewritten[CI]== "Banana" | objnamewritten[CI] == "Sun")|(objnamewritten[CI] == "lemomn" | objnamewritten[CI] == "Sun"))
{
ppup.Height = Window.Current.Bounds.Height;
ppup.IsOpen = true;
}
else
{
ppup1.Height = Window.Current.Bounds.Height;
ppup1.IsOpen = true;
}
}
}
答案 0 :(得分:3)
您的代码中缺少两件事。
以下代码应该有效:
private void common()
{
if (Headername[CI] == "Yellow")
{
if (objnamewritten[CI].Equals("Banana") || objnamewritten[CI].Equals("lemomn") || objnamewritten[CI].Equals("Sun"))
{
ppup.Height = Window.Current.Bounds.Height;
ppup.IsOpen = true;
}
else
{
ppup1.Height = Window.Current.Bounds.Height;
ppup1.IsOpen = true;
}
}
else
{
ppup1.Height = Window.Current.Bounds.Height;
ppup1.IsOpen = true;
}
}