Click here to Skip to main content
13,191,570 members (63,371 online)
Click here to Skip to main content

Stats

61K views
584 downloads
34 bookmarked
Posted 19 May 2008
MIT

Poor Man's LINQ in Visual Studio 2005

, 28 Oct 2010
A way to use LINQ to Objects in C# 2.0 with .NET Framework 2.0
using System;
using System.Collections.Generic;
using System.Text;
using Compatibility.Linq;

namespace Demo
{
	class Program
	{
		public static PoorMansLinq<T> Linq<T>(IEnumerable<T> source)
		{
			return new PoorMansLinq<T>(source);
		}
		public static void Main(string[] args)
		{
			string[] words = new string[] { "Pies", "Are", "Good", "In", "Lovely", "Apples" };
			// Pies Are Good
			Console.WriteLine(string.Join(" ", Linq(words).Take(3).ToArray()));
			// Apples Are Good In Lovely Pies
			Console.WriteLine(string.Join(" ", Linq(words).Sorted().ToArray()));

			int[] numbers = new int[] { 4, 95, 309, 357, 233, 2 };
			// 1000
			Console.WriteLine(Enumerable.Sum(numbers));
			// 666
			Console.WriteLine(Enumerable.Sum(Linq(numbers)
				.Where(delegate(int x) { return x > 300; })));
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License

Share

About the Author

Qwertie
Software Developer None
Canada Canada
Since I started programming when I was 11, I wrote the SNES emulator "SNEqr", the FastNav mapping component, the Enhanced C# programming language (in progress), the parser generator LLLPG, and LES, a syntax to help you start building programming languages, DSLs or build systems.

My overall focus is on the Language of your choice (Loyc) initiative, which is about investigating ways to improve interoperability between programming languages and putting more power in the hands of developers. I'm also seeking employment.

You may also be interested in...

Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171017.1 | Last Updated 29 Oct 2010
Article Copyright 2008 by Qwertie
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid