473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Re: What Lambda expression corresponds to this LINQ query?

Thanks Dan Tallent, that worked. But I defy anybody who thinks this
Lambda expression is more logical than the Linq/Sql equivalent.

For example, both the below fragments yield the same thing (a
reordering from lowest to highest valued int) but I cannot understand
why the .orderby (r =r) works to reorder the numbers.

RL

//var orderLowToHigh = from m in orderHighToLow
// orderby m ascending
// select m;
//Console.WriteLine("HightoLow");
//foreach (int i in orderLowToHigh)
//{ Console.Write("ordrL>>H {0} ,", i); }
////works fine (more logical to understand than the below)
var orderLowToHigh = orderHighToLow.OrderBy(r =>
r).Select(r =r);
foreach (int i in orderLowToHigh)
{ Console.Write("L>>H {0} ", i); } //also works to reorder
from low to high!
Dan Tallent wrote:
I'm not sure exactly what your trying to do but something like this will
work

var HighesttoLowest = numbers

.OrderBy(r =r)

.Select(r =r);
Oct 2 '08 #1
7 2343
There are .OrderByDescending(...) and .ThenByDescending(...) to match
..OrderBy(...) and .ThenBy(...)

Marc
[C# MVP]
Oct 2 '08 #2
raylopez99 wrote:
I have a
couple of years on-off C++ coding experience and about 2 solid months
of C# experience, and I know about 80% of what's there to know about
C#
The first time around that you think that you know 80%, you know about
20%. Keep programming for full time for a few years, and perhaps you
will get there the second time, when you may actually be correct about
the percentage...

:)

--
Göran Andersson
_____
http://www.guffa.com
Oct 2 '08 #3
raylopez99 <ra********@yahoo.comwrote:
learning about dictionaries tonight...I did not realize that a
dictionary is essentially this ordered pair, but with the ability to
use foreach notation--
Another misunderstanding. A dictionary is *not* an ordered pair. It's a
mapping. The point of a dictionary is to be able to efficiently map
from key to value. Most implementations (such as Dictionary) do not
preserve any particular ordering. (Those which do generally have poorer
performance characteristics, as they have more work to do.)

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Oct 3 '08 #4
On Oct 2, 6:37*pm, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
Another misunderstanding. A dictionary is *not* an ordered pair. It's a
mapping.
A pedants point. Noted. I was using an ordered pair to mean
mapping. And binary trees (ordered dictionaries) are not so bad in
performance: a chart in Albahari et al (C# Nutshell, an excellent
book, you should read it and review it) shows SortedDictionary<K,V(a
Red-Black balanced tree) is about five times slower than Dictionary,
which is not radically slower to me (in my mind's eye).

RL
Oct 3 '08 #5
On Oct 3, 1:22*pm, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
>
The results:
SortedDictionary`2: 56779ms
Dictionary`2: 3585ms
Well that's 15 times, not 5 or 6, but I still trust p. 257 of Albahari
et al.
>
(I haven't replied to your other post due to its inflamatory nature, by
the way. As I've said before: if you want sensible discussion, you
should post sensibly and politely.)
Well you're a smarter SOB than I thought Jon.

Plus I had you on a Procrustean Bed--either way you answered I was
going to skewer you, you dumb SOB.

Thanks for your help BTW, without you, I would not be learning C# as
effectively (nor posting here as much).

RL
Oct 3 '08 #6
raylopez99 <ra********@yahoo.comwrote:
The results:
SortedDictionary`2: 56779ms
Dictionary`2: 3585ms

Well that's 15 times, not 5 or 6, but I still trust p. 257 of Albahari
et al.
That just gives a list of results for a single test - it doesn't
indicate complexity. If you increase the size of the dictionary
further, the gap would widen.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Oct 4 '08 #7
On Oct 3, 11:27*pm, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
raylopez99 <raylope...@yahoo.comwrote:
The results:
SortedDictionary`2: 56779ms
Dictionary`2: 3585ms
Well that's 15 times, not 5 or 6, but I still trust p. 257 of Albahari
et al.

That just gives a list of results for a single test - it doesn't
indicate complexity. If you increase the size of the dictionary
further, the gap would widen.

--
Jon Skeet - <sk...@pobox.com>
Web site:http://www.pobox.com/~skeet*
Blog:http://www.msmvps.com/jon.skeet
C# in Depth:http://csharpindepth.com
OK thanks Jon! I see you wisely did not reply to my flame bait...
might have to give up on that, you're too clever.

RL
Oct 5 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Octal | last post by:
How does the lambda library actually works. How does it know how to evaluate _1, how does it recognize _1 as a placeholder, how does it then calculate _1+_2, or _1+2 etc. The source files seem a...
28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
15
by: Matt | last post by:
Hi There, Can anyone explain me the real advantages of (other than syntax) lambda expressions over anonymous delegates? advantage for one over the other. delegate int F(int a); F fLambda = a...
0
by: sneha0608 | last post by:
I am using LINQ.I want to dynamically build a lambda expression which would be passed to the where clause of the Query. i have written the following code: ParameterExpression param =...
5
by: Andrus | last post by:
I need to use lambda expressions or other way to specify default query for dlinq entity type. Code below causes compile error shown in comment. How to fix ? Maybe to use ? Andrus. using...
15
by: K Viltersten | last post by:
I've got a hint from a gentleman here to use the following syntax. public static FileInfo GetFilesRegExp(this DirectoryInfo di, string pat) { Regex re = new Regex(pat); return Array.FindAll(...
20
by: raylopez99 | last post by:
Took a look at all the fuss about "lambda expressions" from Jon Skeet's excellent book "C# in Depth". Jon has an example, reproduced below (excerpt) on lambda expressions. My n00b take: it's...
4
by: CSharper | last post by:
I have following XML <root> <Person id="1"> <Name>a</Name> </Person> <Person id="2"> <Name>b</Name> </Person> </root>
3
by: Marc Gravell | last post by:
A lambda expression is a short form to write a delegate In /this/ case (LINQ-to-Objects): yes - but it could equally be compiled to an Expression, which is very, very different. A lambda...
2
by: Colin Han | last post by:
Hi, all, If I write follow code in c# method. The IDE will compile it to a complex construct method of System.Linq.Expression. Expression<Func<int>ex = () =10; will be compile to:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.