因此,我们试图使用Linq语句显示信息,但我们遇到的问题是如果变量是“”,我们不希望创建一些元素 - 目前我们无法做到这一点,因为我们不能在linq语句中包含'if'语句。我们如何解决这个问题;我们的代码列在下面。在Linq语句中使用'if'语句
(延续 - 我们不想让“x.Phone”元素显示,如果将它设置为“”)
Root = new RootElement ("Student Guide") {
new Section("Contacts"){
from x in AppDelegate.getControl.splitCategories("Contacts")
select (Element)new RootElement(x.Title) {
new Section(x.Title){
(Element)new StyledStringElement("Contact Number",x.Phone) {
BackgroundColor=UIColor.FromRGB(71,165,209),
TextColor=UIColor.White,
DetailColor=UIColor.White,
},
}
},
},
};
虽然,如果不是NullOrEmpty,我将如何使用它创建一个新的'StyledStringElement'?我自己尝试过,但还没有弄明白。 – 2013-05-01 08:49:31
@LoadData为什么不传递一个空字符串?我不知道'StyledSTringElement'是什么:P – LukeHennerley 2013-05-01 09:20:18
因为我们需要它作为StyledStringElement以我们想要的格式显示文本 - 我不知道我们能做到这点的其他原因。 – 2013-05-01 09:42:45