inohilog

/var/log/inohiro.log

List.ToString() とか

ときどきやるミス。もう何度もやっているので対処法を覚えているけど、どうも直感的にいかない。List.ToString() で素直に文字列になってほしいんだけどなあ。

using System;
using System.Collections.Generic;

namespace Sample
{
	class Program
	{
		static void Main( string[] args )
		{
			string hello = "world";
			CharEnumerator cEnum = hello.GetEnumerator();
			List<Char> buf = new List<char>();
			for( int i = 0; i < hello.Length; i++ )
			{
				cEnum.MoveNext();
				buf.Add( cEnum.Current );
			}
			Console.WriteLine( buf.ToString() ); // これはうまくいかない
			Console.WriteLine( new String( buf.ToArray() ) );
			Console.ReadKey();
		}
	}
}

実行結果

System.Collections.Generic.List`1[System.Char]
world