Click here to Skip to main content
15,559,927 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Using IEnumerable nonsense for everything Pin
harold aptroot16-Jul-16 7:10
harold aptroot16-Jul-16 7:10 
GeneralRe: Using IEnumerable nonsense for everything Pin
OriginalGriff16-Jul-16 7:33
mveOriginalGriff16-Jul-16 7:33 
GeneralRe: Using IEnumerable nonsense for everything Pin
harold aptroot16-Jul-16 7:39
harold aptroot16-Jul-16 7:39 
GeneralRe: Using IEnumerable nonsense for everything Pin
Sentenryu18-Jul-16 1:03
Sentenryu18-Jul-16 1:03 
GeneralRe: Using IEnumerable nonsense for everything Pin
harold aptroot18-Jul-16 1:54
harold aptroot18-Jul-16 1:54 
GeneralRe: Using IEnumerable nonsense for everything Pin
Sentenryu18-Jul-16 3:00
Sentenryu18-Jul-16 3:00 
GeneralRe: Using IEnumerable nonsense for everything Pin
harold aptroot18-Jul-16 3:08
harold aptroot18-Jul-16 3:08 
GeneralRe: Using IEnumerable nonsense for everything Pin
Sentenryu18-Jul-16 3:42
Sentenryu18-Jul-16 3:42 
It was hard for me too, but once you understand how the context shifts it becomes way easier. LINQ queries have a different flow from the rest of the imperative code and are best left a little separated from stuff like for loops and complex conditionals, they require you to use the same way of thinking you use when writing SQL. It's not that you are telling the machine what to do, you're telling it what you want done, so you read this:
C#
someList.Where(condition).Select(field)

As "Give me field for all objects where condition is true" instead of "For each object, if condition is true, stuff field on another list".

Truth is, those kind of LINQ queries are just convenience. The real power of LINQ comes when you start using joins and groups, like this example from LINQPad (still on the simple side):
C#
var query =
    from o in Orders
    group o by o.ShipCountry into countryGroups
    select new
    {
        Country = countryGroups.Key,
        Cities =
            from cg in countryGroups
            group cg.ShipPostalCode by cg.ShipCity into cityGroups
            select new
            {
                City = cityGroups.Key,
                PostCodes = cityGroups.Distinct()
            }
    };

that produces this output:
//   Brazil
//      Campinas
//         04876-786
//      Resende
//         08737-363
//      Rio de Janeiro
//         02389-673
//         02389-890
//         05454-876

As much as I can write that using for loops and conditionas, i don't want to write it that way. Also, join's and group's are the only thing I'll ever use query syntax for, they are somewhat easier to understand that way.
GeneralRe: Using IEnumerable nonsense for everything Pin
jfren48418-Jul-16 4:31
jfren48418-Jul-16 4:31 
GeneralRe: Using IEnumerable nonsense for everything Pin
Clifford Nelson18-Jul-16 11:15
Clifford Nelson18-Jul-16 11:15 
GeneralRe: Using IEnumerable nonsense for everything Pin
Mladen Janković18-Jul-16 11:36
Mladen Janković18-Jul-16 11:36 
GeneralRe: Using IEnumerable nonsense for everything Pin
Maarten197718-Jul-16 4:48
Maarten197718-Jul-16 4:48 
GeneralRe: Using IEnumerable nonsense for everything Pin
Herbie Mountjoy18-Jul-16 2:49
professionalHerbie Mountjoy18-Jul-16 2:49 
GeneralRe: Using IEnumerable nonsense for everything Pin
Rob Grainger19-Jul-16 6:56
Rob Grainger19-Jul-16 6:56 
GeneralRe: Using IEnumerable nonsense for everything Pin
#realJSOP16-Jul-16 7:07
mva#realJSOP16-Jul-16 7:07 
GeneralRe: Using IEnumerable nonsense for everything Pin
BillWoodruff16-Jul-16 7:12
professionalBillWoodruff16-Jul-16 7:12 
GeneralRe: Using IEnumerable nonsense for everything Pin
harold aptroot16-Jul-16 7:16
harold aptroot16-Jul-16 7:16 
GeneralRe: Using IEnumerable nonsense for everything Pin
BillWoodruff16-Jul-16 7:20
professionalBillWoodruff16-Jul-16 7:20 
GeneralRe: Using IEnumerable nonsense for everything Pin
Marc Clifton16-Jul-16 15:47
mvaMarc Clifton16-Jul-16 15:47 
GeneralRe: Using IEnumerable nonsense for everything Pin
BillWoodruff16-Jul-16 19:45
professionalBillWoodruff16-Jul-16 19:45 
GeneralRe: Using IEnumerable nonsense for everything Pin
Marc Clifton17-Jul-16 4:55
mvaMarc Clifton17-Jul-16 4:55 
GeneralRe: Using IEnumerable nonsense for everything Pin
Jono Stewart18-Jul-16 5:10
Jono Stewart18-Jul-16 5:10 
GeneralRe: Using IEnumerable nonsense for everything Pin
Rob Grainger19-Jul-16 23:21
Rob Grainger19-Jul-16 23:21 
GeneralRe: Using IEnumerable nonsense for everything Pin
jgakenhe16-Jul-16 9:37
professionaljgakenhe16-Jul-16 9:37 
GeneralRe: Using IEnumerable nonsense for everything Pin
Sander Rossel17-Jul-16 1:08
professionalSander Rossel17-Jul-16 1:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.