Solved

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

Posted on 2010-11-20
3
527 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

806 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