<p>I seem to be missing something about LINQ.  To me, it looks like it's taking some of the elements of SQL that I like the least and moving them into the C# language and using them for other things.</p>

<p>I mean, I could see the benefit of using SQL-like statements on things other than databases.  But if I wanted to write SQL, well, why not just write SQL and keep it out of C#?  What am I missing here?</p>

[{'answer_id': 21287, 'author': 'TheSmurf', 'author_id': 1975282, 'author_profile': 'https://Stackoverflow.com/users/1975282', 'pm_score': 2, 'selected': False, 'text': '<p>The point is that LINQ integrates your queries into your primary programming language, allowing your IDE to provide you with some facilities (Intellisense and debug support, for example) that you otherwise would not have, and to allow the compiler to type-check your SQL code (which is impossible with a normal string query).</p>\n'}, {'answer_id': 21292, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 6, 'selected': True, 'text': "<p>LINQ is not about SQL. LINQ is about being apply functional programming paradigmns on objects.</p>\n\n<p>LINQ to SQL is an ORM built ontop of the LINQ foundation, but LINQ is much more. I don't use LINQ to SQL, yet I use LINQ all the time.</p>\n\n<p>Take the task of finding the intersection of two lists:</p>\n\n<p>Before LINQ, this tasks requires writing a nested foreach that iterates the small list once for every item in the big list O(N*M), and takes about 10 lines of code.</p>\n\n<pre><code>foreach (int number in list1)\n{\n    foreach (int number2 in list2)\n    {\n        if (number2 == number)\n        {\n            returnList.add(number2);\n        }\n    }\n}\n</code></pre>\n\n<p>Using LINQ, it does the same thing in one line of code:</p>\n\n<pre><code>var results = list1.Intersect(list2);\n</code></pre>\n\n<p>You'll notice that doesn't look like LINQ, yet it is. You don't need to use the expression syntax if you don't want to.</p>\n"}, {'answer_id': 21331, 'author': 'ScottKoon', 'author_id': 1538, 'author_profile': 'https://Stackoverflow.com/users/1538', 'pm_score': 3, 'selected': False, 'text': "<p>So the really, really big deal about LINQ has nothing to do with Linq to SQL. It's about the enhancements it brought to the C# language itself.</p>\n"}, {'answer_id': 21418, 'author': 'Wedge', 'author_id': 332, 'author_profile': 'https://Stackoverflow.com/users/332', 'pm_score': 3, 'selected': False, 'text': '<p>LINQ is not just an ORM system, as Jonathan pointed out it brings a lot of functional programming elements to C#. And it lets you do a lot of "database-y" things in regular C# code. It\'s difficult to explain just how incredibly powerful that can be. Consider how much having solid, well designed generic data structures (such as list, stack, dictionary/hash, etc.) included in common frameworks has improved the state of development in modern languages. Precisely because using these data structures is very common and reducing the intellectual overhead of using them is a huge benefit. LINQ doesn\'t do anything you can\'t do yourself, but it makes a lot of operations a lot more straightforward and a lot easier.</p>\n\n<p>Consider the time-honored example of removing duplicates from a non-ordered list. In a lower level language like C or C++ you\'d probably have to sort the list and maintain two indices into the list as you removed dupes. In a language with hashes (Java, C#, Javascript, Perl, etc.) you could create a hash where the keys are the unique values, then extract the keys into a new list. With LINQ you could just do this:</p>\n\n<pre><code>int[] data = { 0, 1, 3, 3, 7, 8, 0, 9, 2, 1 };\n\nvar uniqueData = data.GroupBy(i =&gt; i).Select(g =&gt; g.Key);\n</code></pre>\n'}, {'answer_id': 80709, 'author': 'Benjol', 'author_id': 11410, 'author_profile': 'https://Stackoverflow.com/users/11410', 'pm_score': 4, 'selected': False, 'text': '<p>Before:</p>\n\n<pre><code>// Init Movie\nm_ImageArray = new Image[K_NB_IMAGE];\n\nStream l_ImageStream = null;\nBitmap l_Bitmap = null;\n\n// get a reference to the current assembly\nAssembly l_Assembly = Assembly.GetExecutingAssembly();\n\n// get a list of resource names from the manifest\nstring[] l_ResourceName = l_Assembly.GetManifestResourceNames();\n\nforeach (string l_Str in l_ResourceName)\n{\n    if (l_Str.EndsWith(".png"))\n    {\n        // attach to stream to the resource in the manifest\n        l_ImageStream = l_Assembly.GetManifestResourceStream(l_Str);\n        if (!(null == l_ImageStream))\n        {\n            // create a new bitmap from this stream and \n            // add it to the arraylist\n            l_Bitmap = Bitmap.FromStream(l_ImageStream) as Bitmap;\n            if (!(null == l_Bitmap))\n            {\n                int l_Index = Convert.ToInt32(l_Str.Substring(l_Str.Length - 6, 2));\n                l_Index -= 1;\n                if (l_Index &lt; 0) l_Index = 0;\n                if (l_Index &gt; K_NB_IMAGE) l_Index = K_NB_IMAGE;\n                m_ImageArray[l_Index] = l_Bitmap;\n            }\n            l_Bitmap = null;\n            l_ImageStream.Close();\n            l_ImageStream = null;\n        } // if\n    } // if\n} // foreach\n</code></pre>\n\n<p>After:</p>\n\n<pre><code>Assembly l_Assembly = Assembly.GetExecutingAssembly();\n\n//Linq is the tops\nm_ImageList = l_Assembly.GetManifestResourceNames()\n    .Where(a =&gt; a.EndsWith(".png"))\n    .OrderBy(b =&gt; b)\n    .Select(c =&gt; l_Assembly.GetManifestResourceStream(c))\n    .Where(d =&gt; d != null)  //ImageStream not null\n    .Select(e =&gt; Bitmap.FromStream(e))\n    .Where(f =&gt; f != null)  //Bitmap not null\n    .ToList();\n</code></pre>\n\n<p>Or, alternatively (<em>query syntax</em>):</p>\n\n<pre><code>Assembly l_Assembly = Assembly.GetExecutingAssembly();\n\n//Linq is the tops\nm_ImageList = (\n    from resource in l_Assembly.GetManifestResourceNames()\n    where resource.EndsWith(".png")\n    orderby resource\n    let imageStream = l_Assembly.GetManifestResourceStream(resource)\n    where imageStream != null\n    let bitmap = Bitmap.FromStream(imageStream)\n    where bitmap != null)\n    .ToList();\n</code></pre>\n'}, {'answer_id': 641324, 'author': 'Jacob Stanley', 'author_id': 72821, 'author_profile': 'https://Stackoverflow.com/users/72821', 'pm_score': 2, 'selected': False, 'text': '<p>Because linq is really monads in sql clothing, I\'m using it on a project to make asynchronous web requests with the continuation monad, and it\'s proving to work really well!</p>\n\n<p>Check out these articles:\n<a href="http://www.aboutcode.net/2008/01/14/Async+WebRequest+Using+LINQ+Syntax.aspx" rel="nofollow noreferrer">http://www.aboutcode.net/2008/01/14/Async+WebRequest+Using+LINQ+Syntax.aspx</a>\n<a href="http://blogs.msdn.com/wesdyer/archive/2008/01/11/the-marvels-of-monads.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/wesdyer/archive/2008/01/11/the-marvels-of-monads.aspx</a></p>\n\n<p>From the first article:</p>\n\n<pre><code>    var requests = new[] \n    {\n        WebRequest.Create("http://www.google.com/"),\n        WebRequest.Create("http://www.yahoo.com/"),\n        WebRequest.Create("http://channel9.msdn.com/")\n    };\n\n    var pages = from request in requests\n                select\n                    from response in request.GetResponseAsync()\n                    let stream = response.GetResponseStream()\n                    from html in stream.ReadToEndAsync()\n                    select new { html, response };\n\n    foreach (var page in pages)\n    {\n        page(d =&gt;\n        {\n            Console.WriteLine(d.response.ResponseUri.ToString());\n            Console.WriteLine(d.html.Substring(0, 40));\n            Console.WriteLine();\n        });\n    }\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/21280', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2147/']