-  [WT]  [PS]  [Home] [Manage]

Posting mode: Reply
  1.   (reply to 5061)
  2. (for post and file deletion)
/pr/ - Programming
  • Supported file types are: C, CSS, DOC, DOCX, GIF, H, JAVA, JPG, PDF, PNG, SVG, SWF, TXT, WEBM
  • Maximum file size allowed is 10000 KB.
  • Images greater than 200x200 pixels will be thumbnailed.
  • Currently 389 unique user posts. View catalog

  • Blotter updated: 2011-01-12 Show/Hide Show All

There's a new /777/ up, it's /gardening/ Check it out. Suggest new /777/s here.

Movies & TV 24/7 via Channel7: Web Player, .m3u file. Music via Radio7: Web Player, .m3u file.

WebM is now available sitewide! Please check this thread for more info.

Neckbearded Basement Dweller 17/08/16(Wed)05:58 No. 5061

File 150285589835.jpg - (9.09MB , 3800x5244 , jasmine4.jpg )

results.Sort((g1, g2) => g2.depth.CompareTo(g1.depth));

Can someone explain to me what the hell this C# does?

results is a System.Collections.Generic.List

It's some kind of interface shortcut I guess? But what is => and why write it like that, does it save CPU cycles or just time for the coder himself?

Neckbearded Basement Dweller 17/08/18(Fri)05:06 No. 5064

=> is used to define anonymous functions, or lambdas. The call is passing to Sort() a function that takes two parameters and returns an int representing the comparison between the parameters.

Lambdas don't just save the programmer time, they also make the code clearer (as long as you understand the syntax). The alternative would be to define a one-off static function somewhere and pass it. With a lambda, related code stays closer, which makes it easier to read as you don't have to hunt around the codebase for various functions.
Consider figuring out what this does if no lambdas were involved:

return someList .Where(x => x.EntryType.IsFile()) .OrderBy(x => x.OrderIndex) .ThenBy(x => x.Name, StringComparer.InvariantCultureIgnoreCase) .Select(x => client.Concatenate(parentString, x.Name)) .ToList();

Neckbearded Basement Dweller 17/08/18(Fri)05:06 No. 5065

Darn, the formatting got completely fucked. Oh, well.

Nattack!upUGcHlgU2 17/08/18(Fri)10:55 No. 5066


Here bud

Function currying and lambdas combine to make a thing called Streams (as my college puts it anyway), they are not quite the same as a filestream, however.

It's a great thing to learn, a bit tricky at first but can eliminate the need for complicated nested loops with slightly less complicated nested lambdas.

Neckbearded Basement Dweller 17/09/04(Mon)00:29 No. 5071

File 150447779632.jpg - (181.57KB , 650x922 , jasmine2.jpg )

Thanks for explaining! I think I'll need to do a bit more research on lambdas before I grasp them.

[Return] [Entire Thread] [Last 50 posts]

Delete post []
Report post