问题
based on this XML
<schedule>
<flight="A01">
-<Aircraft mdy="Thursday, September 1, 2016" Destination="Mykonos"
Source="Athens" ID="A320">
<FROM>ATH</FROM>
<TO>MYK</TO>
<Miles>300</Miles>
</Aircraft>
</flight>
</schedule>
I have the following code
XDocument reservation = XDocument.Load("schedulemanager.xml");
var r = (from element in XDocument.Load("schedulemanager.xml").Descendants("Aircraft")
let type = element.Attribute("mdy").Value
select type == dtArrival.Text ? MessageBox.Show("Dates are same") : type != dtArrival.Text ? MessageBox.Show("Dates not matching") : 0).FirstOrDefault();
The first query compares datepicker date that chosen by the user, with the mdy attribute "Thursday, September 1, 2016". If dates are same, a message box appears. This works fine. But when I'm trying to call a method (returns void) an error message appears "Type of conditional expression cannot be determined because there is no implicit conversion between 'void' and 'System.Windows.Forms.DialogResult' "
I want something like this
var r = (from element in
XDocument.Load("schedulemanager.xml").Descendants("Aircraft")
let type = element.Attribute("mdy").Value
select type == dtArrival.Text ? makeReservation()
Also, how can I have multiple if statements in linq? Something like
if select mdy==dateTimePicker && id == flightID && something==sth...then
Another question is how a variable can be cancelled/deallocated after a time limit? For instance, how reservation can be cancelled after two days from booking. I have read about timestamp but I don't know if I'm right.
Thanks in advance, any help will be highly appreciated.
来源:https://stackoverflow.com/questions/39306498/linq-xml-calling-c-sharp-method