LoginSignup
1
3

More than 5 years have passed since last update.

[C#] 配列の全要素を別の要素に変換する

Posted at

文字列を数値に変換することはよくあるのですが、下記のように文字列配列の全要素を数値に変換するにはどうするのか調べたのでメモ書き。

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int.Parse(Console.ReadLine());
            long[] nums = Array.ConvertAll(
                Console.ReadLine().Split(' '),
                new Converter<string,long>( s => long.Parse(s) ));

            Console.WriteLine("{0} {1} {2}",
                nums.Min(),
                nums.Max(),
                nums.Sum()
                );
        }
    }
}
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3