Solved

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

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

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
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
Comment Utility
thanks very much,

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

0
 
LVL 74

Expert Comment

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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now