Skip to content

Instantly share code, notes, and snippets.

@N-Carter
Created July 21, 2011 09:55
Show Gist options
  • Save N-Carter/1096890 to your computer and use it in GitHub Desktop.
Save N-Carter/1096890 to your computer and use it in GitHub Desktop.
Generic List extension method
using System;
using System.Collections.Generic;
namespace Testbed
{
static class Extensions
{
public static T ElementFromWrappedIndex<T>(this List<T> list, int i)
{
return list[i];
}
}
class MainClass
{
public static void Main(string[] args)
{
var list = new List<int>() {1, 2, 4, 8, 16, 32};
for(int i = 0; i < list.Count; ++i)
Console.WriteLine("{0}: {1}", i, list.ElementFromWrappedIndex(i));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment