I am reading data from XML file using from..select linq query, the data is huge. the biggest set of data I can read is 1100 lines, each line consists of 100s of characters. This causes my phone to hang and application crashes. On Emulator, it works fine,although it takes considerable amount of time to load.
Now what I want, is based on some conditions I want include the data elements in the query. As anexample, what I have now is…
var dataSet = from r in something.Elements("chapter")
select new dictChapter{
Name = r.Attribute("Name").Value,
Desc1 = r.Attribute("Description1").Value,
Desc2 = r.Attribute("Description2").Value,
Desc3 = r.Attribute("Description3").Value
};
ListBox.DataContext = dataSet;
But I want to select the Descriptions based on the settings. I want something like (I know it doesn’t work, but I want explain what I want to do)
var dataSet = from r in something.Elements("chapter")
select new dictChapter{
Name = r.Attribute("Name").Value,
if (ShowDesc1 == true)
Desc1 = r.Attribute("Description1").Value,
if (ShowDesc2 == true)
Desc2 = r.Attribute("Description2").Value,
if (ShowDesc3 == true)
Desc3 = r.Attribute("Description3").Value
};
ListBox.DataContext = dataSet;
- How can I achieve this in C Sharp?
- Is there any better solution to my problem?
Thanks very much
Use the conditional operator “?:“