Created
January 10, 2012 18:01
-
-
Save jhartwell/1590261 to your computer and use it in GitHub Desktop.
IterableTuple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Written by Jonathan Hartwell | |
| * http://www.dontbreakthebuild.com | |
| * 1/10/2012 | |
| * | |
| * | |
| */ | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Collections; | |
| using System.Linq; | |
| using System.Text; | |
| namespace ConsoleApplication1 | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var t1 = IterableTuple.Create(1.5, 12, "string", 15, 69); | |
| foreach (var it in t1) | |
| { | |
| Console.WriteLine(it); | |
| } | |
| Console.ReadLine(); | |
| } | |
| } | |
| public class IterableTuple : IEnumerable | |
| { | |
| private List<dynamic> storage; | |
| int position = -1; | |
| public IterableTuple(params dynamic[] args) | |
| { | |
| storage = new List<dynamic>(); | |
| for (int i = 0; i < args.Length; i++) | |
| { | |
| storage.Add(args[i]); | |
| } | |
| } | |
| public static IterableTuple Create(params dynamic[] args) | |
| { | |
| return new IterableTuple(args); | |
| } | |
| public dynamic this[int i] | |
| { | |
| get | |
| { | |
| if (i < storage.Count) | |
| { | |
| return storage[i]; | |
| } | |
| else | |
| { | |
| throw new IndexOutOfRangeException(); | |
| } | |
| } | |
| } | |
| public IEnumerator GetEnumerator() | |
| { | |
| return storage.GetEnumerator(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment