473,732 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.WriteLi ne("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 2363
There are .OrderByDescend ing(...) and .ThenByDescendi ng(...) 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********@yah oo.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 misunderstandin g. 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.co m>
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.co mwrote:
Another misunderstandin g. 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 SortedDictionar y<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.co mwrote:
>
The results:
SortedDictionar y`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********@yah oo.comwrote:
The results:
SortedDictionar y`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.co m>
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.co mwrote:
raylopez99 <raylope...@yah oo.comwrote:
The results:
SortedDictionar y`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.co m>
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
2160
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 bit complicated so any explanation would be appreciated. Thanks
28
16417
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 write a safe but easy implementation (i.e. no codedom) for an IBindingListView.Filter (by compiling to a Predicate<T>). Anybody know if this is possible at all? Marc
15
4844
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 =a++; F fAnonymous = delegate(int a) { return a++; }; fLambda(1);
0
1226
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 = Expression.Parameter(typeof(typename),"type"); MemberExpression member = Expression.Property(Expression.Constant(param), "Name"); ParameterExpression constant = Expression.Parameter(typeof(string), "Value"); I have to associate a...
5
2115
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 System; using System.Linq;
15
4493
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( di.GetFiles(), (f) =re.IsMatch(f.Name));
20
3996
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 like SQL and those 'high level' languages that try to be too clever by half and pack a lot of syntax in as short a space as possible. Like Egyptian hieroglyphics, like Chinese, like those non-alphabet languages, it's just way too much information...
4
5096
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
221
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 *statement*, on the other hand, is always a delegate. Marc
2
3530
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: Expression<Func<int>ex = Expression.Lambda<Func<int>(Expression.Literal(10)) It is so smart. I can travel in this expression tree. I can do some smart abilities on this design. Now, I want write a console application. If user input follow string from console,...
0
8774
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectóplanning, coding, testing, and deploymentówithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.