How can I learn LINQ?

MitjaHd

New member
Joined
Jun 23, 2019
Messages
3
Programming Experience
Beginner
I'm a begginer and started doing some coding on codewars, website where you code simple algorithms. And I found out I don't really have good understand of core C# concepts, I saw I could do a lot of stuff using LINQ instead of for and foreach statements. I'm struggling with learning LINQ, I read some tutorials and watch some youtube videos, but it seems too hard to me, perhaps I lack enough exerience in other concepts like OOP (which I understand, but not completely). What should I know before learning LINQ and what is a good palce to learn it? Thanks.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
2,286
Location
Sydney, Australia
Programming Experience
10+
It helps to have a decent understanding of SQL before learning LINQ because LINQ is pretty much performing SQL-like queries in managed code on managed objects.
 

Skydiver

Well-known member
Joined
Apr 6, 2019
Messages
214
Location
Virginia Beach, VA
Programming Experience
10+
Or alternatively, another way to learn how to use the extension methods that LINQ ends up being converted to by the compiker, immerse yourself into functional programming, and the functional way of thinking.
 

MitjaHd

New member
Joined
Jun 23, 2019
Messages
3
Programming Experience
Beginner
Alright will look deeper into SQL, I already know few commands and can use it with PHP to add and get stuff from database, etc. Then slowly going into LINQ, I got really confused when I saw lambda (=>).
 

Skydiver

Well-known member
Joined
Apr 6, 2019
Messages
214
Location
Virginia Beach, VA
Programming Experience
10+
Are you actually using LINQ query syntax?
Code:
var highScores = from student in students
                 where student.ExamScores[exam] > score
                 select new {Name = student.FirstName, Score = student.ExamScores[exam]};
Or are you using the method syntax?
Code:
var highScores = students.Where(student => student.ExamScores[exam] > score)
                          .Select(student => new { Name = student.FirstName, Score = student.ExamScores[exam] });
If you are using the former, then yes, understanding SQL with help you a lot. If you are using the latter, then functional programming may help more.

(See Query Syntax and Method Syntax in LINQ)
 

MitjaHd

New member
Joined
Jun 23, 2019
Messages
3
Programming Experience
Beginner
I guess I'm trying to use the methos syntax. Thanks for examples.
 
Top Bottom