Last active
August 29, 2015 14:11
-
-
Save TAK-EMI/bedeac3e1e799149fc74 to your computer and use it in GitHub Desktop.
C#のEnumeratorを、C++のstd::vectorなんかのイテレータっぽく使うサンプル。
This file contains 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
List<int> list = new List<int> { 0, 1, 2, 3, 4 }; | |
foreach(int i in list) | |
System.Console.Write(i + ", "); | |
System.Console.WriteLine(""); | |
int[] array = list.ToArray(); | |
foreach(int i in array) | |
System.Console.Write(i + ", "); | |
System.Console.WriteLine(""); | |
var e = list.GetEnumerator(); | |
for(int i = 0; i < 4; ++i) | |
e.MoveNext(); | |
List<int>.Enumerator enu = e; | |
System.Console.WriteLine(e.Current); | |
System.Console.WriteLine(enu.Current); | |
//list.Remove(0); | |
list.RemoveAt(0); | |
foreach(int i in list) | |
System.Console.Write(i + ", "); | |
System.Console.WriteLine(""); | |
System.Console.WriteLine(e.Current); | |
System.Console.WriteLine(enu.Current); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
あ、仰るとおりですね!
list.RemoveAt(0);が想定したものです。
ご指摘ありがとうございます!
修正しておきますね。