But it does not accept AirNames or index after 'br'.
It should accept these values because I've used ToList() to convert this to a dynamic array.
Please send your project directly to v-dedong@microsoft.com for more analyses, please attach your ConsoleApp here with the link of your issue on
www.asp.net
I didnt put List() at the end. The following code i have tried so far.
List<string> airline1 = new List<string>();
var acname = new ArrayList();
for (int i = 0; i <= bt.Count - 1; i++)
{
var f= fs[i].AirLineName;
foreach (var item in f)
{
acname.Add(item.Value);
airline1.Add(item.Value);
}
}
I tried these because the 'br' value will dynamically increase or reduce. so i can't go with var
result1=br[2].Airlinename.
Now, the proble is if br[3] has -> Airline[3],Duration[3] means, how to store these values into seperately..
In normal it returns all the Airline name under One variable like
br:
somevar[0]-Jetairways
somevar[1]-Jetairways
somevar[2]-Jetairways
If br[3] has Airline[3].
It should show as,
somevar[0]-Jetairways,Flyemirates,Airfrance. Not like above sample. Thanks a lot.
Thirisangu
Member
26 Points
193 Posts
Read Values in 'Var' Keyword using Foreach in Linq
Nov 01, 2012 01:27 PM|LINK
Hi all,
Here is my Linq.
var bt = from Main in add.Descendants(ns + "PricedItinerary") select new { AirLineName = Main.Elements(ns + "AirItinerary").Elements(ns + "OriginDestinationOptions").Elements(ns + "OriginDestinationOption").Elements(ns + "FlightSegment").Elements(ns + "MarketingAirline").Attributes("Name").ToList(), Duration = Main.Elements(ns + "AirItinerary").Elements(ns + "OriginDestinationOptions").Elements(ns + "OriginDestinationOption").Elements(ns + "FlightSegment").Attributes("Duration").ToList(), };Var 'bt' holds value like,
[0]--> AirLineName [0] , Duration[0].==> It has one AirLineName("New york").Duration( 1 hour)
[1]--> AirLineName [1], Duration [1].==> It has two AirLineName("London"",New York"). Duration(1 hour, 5 hour)
[2]--> AirLineName [0], Duration [0].==> Like wise here
[3]--> AirLineName[2], Duration[2].
Here, How to Write Foreach to Read the Values in AirLinenames. ("London","Newyork").
Please,Let me know more information.
Thanks in advance.
Linq
rkbvasanths@...
Participant
959 Points
238 Posts
Re: Read Values in 'Var' Keyword using Foreach in Linq
Nov 01, 2012 02:07 PM|LINK
foreach(var al in bt)
{
Console.WriteLine(al.AirLineName);
}
Thanks,
Vasanth R, MCTS(SQL 2005 & SQL 2008 BI), MCP
http://dotnetcodeguide.blogspot.com
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Read Values in 'Var' Keyword using Foreach in Linq
Nov 02, 2012 01:37 AM|LINK
I'm afraid you have to use "foreach" to loop "bt", and then you can also try to use nested foreach to loop "AirLineName" and "Duration".
Linq
Thirisangu
Member
26 Points
193 Posts
Re: Read Values in 'Var' Keyword using Foreach in Linq
Nov 02, 2012 03:49 AM|LINK
hi ,
Thanks for your replay. Can you give some idea about how to do that?
Thanks again.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Read Values in 'Var' Keyword using Foreach in Linq
Nov 02, 2012 03:54 AM|LINK
is your AirName or some properties like this containing an array?
Thirisangu
Member
26 Points
193 Posts
Re: Read Values in 'Var' Keyword using Foreach in Linq
Nov 02, 2012 03:59 AM|LINK
hi,
Not in array. Please look at my Code. I described just how it is look like when i use trace point over bt.
Thanks again.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Read Values in 'Var' Keyword using Foreach in Linq
Nov 02, 2012 04:05 AM|LINK
Hi again,
You can first fetch out the 3rd item, and then use foreach:
Hello, var bt = (from Main in add.Descendants(ns + "PricedItinerary") select new { AirLineName = Main.Elements(ns + "AirItinerary").Elements(ns + "OriginDestinationOptions").Elements(ns + "OriginDestinationOption").Elements(ns + "FlightSegment").Elements(ns + "MarketingAirline").Attributes("Name").ToList(), Duration = Main.Elements(ns + "AirItinerary").Elements(ns + "OriginDestinationOptions").Elements(ns + "OriginDestinationOption").Elements(ns + "FlightSegment").Attributes("Duration").ToList(), }).ToList(); var result1 = bt[2].AirNames; var result2 = bt[2].Duration; foreach(var s in result1) { ……………… } foreach(var t in result2) { ……………… }Thirisangu
Member
26 Points
193 Posts
Re: Read Values in 'Var' Keyword using Foreach in Linq
Nov 02, 2012 04:14 AM|LINK
Hi,
I tried with these codes.,
But it does not accept AirNames or index after 'br'. Normally, br holds all these value.
But not in br[0]->Airlinename[0],Duration[0], br[1]->Airlinename[2],Duration[2].
It Just , br=> [0]->Airlinename[0],Duration[0], [1]->Airlinename[2],Duration[2].
Thanks again.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Read Values in 'Var' Keyword using Foreach in Linq
Nov 02, 2012 04:18 AM|LINK
It should accept these values because I've used ToList() to convert this to a dynamic array.
Please send your project directly to v-dedong@microsoft.com for more analyses, please attach your ConsoleApp here with the link of your issue on www.asp.net
Thirisangu
Member
26 Points
193 Posts
Re: Read Values in 'Var' Keyword using Foreach in Linq
Nov 02, 2012 04:46 AM|LINK
Hi,
I didnt put List() at the end. The following code i have tried so far.
List<string> airline1 = new List<string>(); var acname = new ArrayList(); for (int i = 0; i <= bt.Count - 1; i++) { var f= fs[i].AirLineName; foreach (var item in f) { acname.Add(item.Value); airline1.Add(item.Value); } }I tried these because the 'br' value will dynamically increase or reduce. so i can't go with var result1=br[2].Airlinename.
Now, the proble is if br[3] has -> Airline[3],Duration[3] means, how to store these values into seperately..
In normal it returns all the Airline name under One variable like
br:
somevar[0]-Jetairways
somevar[1]-Jetairways
somevar[2]-Jetairways
If br[3] has Airline[3].
It should show as,
somevar[0]-Jetairways,Flyemirates,Airfrance. Not like above sample. Thanks a lot.