Чтобы максимально приблизиться к вашему синтаксису, это сработает, если вас интересует только один тип (в данном примере это int):
static void Main(string[] args)
{
if (args.Length == 0) { args = new string[] { "3", "43", "6" }; }
IEnumerator<int> scanner = (from arg in args select int.Parse(arg)).GetEnumerator();
while (scanner.MoveNext())
{
Console.Write("{0} ", scanner.Current);
}
}
Вот еще более крутая версия, которая позволяет вам получить доступ к любому типу, который поддерживается реализацией IConvertible в строке:
static void Main(string[] args)
{
if (args.Length == 0) { args = new string[] { "3", "43", "6" }; }
var scanner = args.Select<string, Func<Type, Object>>((string s) => {
return (Type t) =>
((IConvertible)s).ToType(t, System.Globalization.CultureInfo.InvariantCulture);
}).GetEnumerator();
while (scanner.MoveNext())
{
Console.Write("{0} ", scanner.Current(typeof(int)));
}
}
Просто передайте другой тип оператору "typeof" в цикле while, чтобы выбрать тип.
Для обеих этих версий требуются последние версии C # и .NET Framework.