Off Topic > Off Topic

Programming Megathread

Pages: << < (50/241) > >>

Maxwell.:

http://88.144.125.20/php.php

practising with database work

ZSNO:


--- Quote from: Jairo on December 30, 2015, 06:08:44 PM ---I thought this thread had been revamped to include web development too

--- End quote ---
Looks like web design more than programming anything, but idk what you did

AndroFox:

for some reason I always cringe at programming

Ipquarx:

Man I love LINQ

For those of you who don't know what LINQ is (Probably the majority) it's sort-of like SQL except for coding (in C#). Like if you for example have an array of objects named travelLocations you can do:
var selections = from location in travelLocations
                where location.planePrice < 575.36
                select location;

foreach(var location in selections)
    Console.WriteLine(location.description);

And that will give you the description of every single travel location that has a plane price of less than $575.36

My specific use of LINQ in this case was that I had a 2D array of chars (char[][]) that I was using to construct a larger string. Each one of the arrays inside of it was a seperate line, so it was an array of strings basically, except I needed to use chars because I can't individually set the chars of a string without wonky manipulation.

So I thought to myself "What's the easiest way to merge this back into a string how I want it?"
And then I tried out using LINQ
string final = String.Join("\r\n",
                           (from x in stringBuilt
                           select String.Join("", x).TrimEnd(' ')).ToArray());

It selects every char[] in the char[][], and selects itself joined together and trimmed. Then it takes all that match that and puts every single one into an array (So we have an array of strings, each one is a seperate line) and then merges them together with a newline.

That saves probably 15 lines of code and is probably similarly efficient. Yay laziness!

Headcrab Zombie:

Yeah I use LINQ pretty extensively
Although I tend to use it in the other format (not sure what it's called/if it has a specific name) like so:

var selections = travelLocations.Where(l => l.planePrice < 576.36).Select(l => l.location);

Not sure why, I've used both but at some point I just stuck with that one

Pages: << < (50/241) > >>

Go to full version