Solved

how to check value if it is between two values in linq?

Posted on 2010-11-20
3
529 Views
Last Modified: 2013-12-17
hi,

I was trying to check value if it is between two values from xml file, so how to perform between "something" and "something else" using linq?


here is my try
var countries = from country in xmlDoc.Descendants("IpCountries")
                               where Dot2LongIP.ToString() between country.Element("beginningIp").Value and country.Element("endingIp").Value
                               select new
                               {
                                   hostIPAddress = country.Element("beginningIp").Value,
                                   hostName = country.Element("endingIp").Value,
                                   hostLocation = country.Element("countryCC").Value,
                                   hostBrowserType = country.Element("countryCCC").Value,
                                   hostBrowserVersion = country.Element("country").Value,
                               };

Open in new window

0
Comment
Question by:njgroup
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 34179933
Try this:
var countries = from country in xmlDoc.Descendants("IpCountries")
                               let longIp = Dot2LongIP
                               where longIP >= Convert.ToInt64(country.Element("beginningIp").Value) && longIP <= Convert.ToInt64(country.Element("endingIp").Value)
                               select new
                               {
                                   hostIPAddress = country.Element("beginningIp").Value,
                                   hostName = country.Element("endingIp").Value,
                                   hostLocation = country.Element("countryCC").Value,
                                   hostBrowserType = country.Element("countryCCC").Value,
                                   hostBrowserVersion = country.Element("country").Value,
                               };

Open in new window

0
 

Author Closing Comment

by:njgroup
ID: 34180130
thanks very much,

I was looking for something better than A grade to assign :))

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34180519
NP. Glad to help  :)
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question