inohiro.tumblr.com

this is inohiro's tumblr.

List<Char>.ToString() とか
C# | 編集

ときどきやるミス。もう何度もやっているので対処法を覚えているけど、どうも直感的にいかない。List<Char>.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();
}
}
}

More Information