Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Poor Man's LINQ in Visual Studio 2005

, 29 Oct 2010 MIT
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 Trapeze Software, Inc.
Canada Canada
Since I started programming when I was 11, I wrote the SNES emulator "SNEqr", the FastNav mapping component, and LLLPG, among other things. Now I'm old.
 
In my spare time I'm developing a system called Loyc (Language of your choice), which will include an enhanced C# compiler. Many programs have an add-in architecture; why not your programming language? I'm also looking for a life partner. Oh hi future wife! Wazzap.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141220.1 | Last Updated 29 Oct 2010
Article Copyright 2008 by Qwertie
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid