Working in a standard visual studio 2013 web app, I realized that it seems not possible to resolve the System.Linq namespace, e.g. on
mylist.Sum(...)
in a class when using System.Linq is missing in the code. You have to add
using System.Linq
manually, which is possible (references are added to project). What is the reason for this?
All the LINQ methods are extension methods. The compiler only knows which extension methods you're interested based on which using
directives are present in your code, e.g.
// Imports extension methods from all static classes in the
// System.Linq namespace
using System.Linq;
// C# 6 only: imports extension methods from System.Linq.Enumerable only
using static System.Linq.Enumerable;
That's just how extension methods work... it's not LINQ-specific.
See more on this question at Stackoverflow