linq XML calling c# method

非 Y 不嫁゛ 提交于 2020-01-16 11:39:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!