473,804 Members | 3,469 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 2367
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
2165
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
16435
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
4855
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
1230
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
2119
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
4498
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
4002
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
5103
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
3534
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
9708
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10589
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...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10327
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
9161
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
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
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
4302
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
3
2999
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.