「C#」LINQのSelectでIEnumerableの値を取得する

2022年1月4日

書式
IEnumerable<double> コレクション名 = new[] { 要素1, 要素2,xxx };
関数
public static System.Collections.Generic.IEnumerable<TResult> Select<TSource,TResult>
(this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,TResult> selector);
LINQのSelectメソッドを使うと、配列・コレクションの各要素から必要な要素だけを取り出すということが出来ます。
戻り値:source の各要素に対して変換関数を呼び出した結果として得られる要素を含む IEnumerable<T>。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
using System;
using System.Collections.Generic;
using System.Linq;
namespace infoapp
{
class Program
{
static void Main(string[] args)
{
IEnumerable<double> cft = new[] { 3.03, 4.14, 5.25, 6.36 };
Console.WriteLine(String.Join(", ", cft.Select(j => j)));
Console.ReadKey();
}
}
}
using System; using System.Collections.Generic; using System.Linq; namespace infoapp { class Program { static void Main(string[] args) { IEnumerable<double> cft = new[] { 3.03, 4.14, 5.25, 6.36 }; Console.WriteLine(String.Join(", ", cft.Select(j => j))); Console.ReadKey(); } } }
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace infoapp
{
    class Program
    {
        static void Main(string[] args)
        {
 
            IEnumerable<double> cft = new[] { 3.03, 4.14, 5.25, 6.36 };
 
            Console.WriteLine(String.Join(", ", cft.Select(j => j)));
        
            Console.ReadKey();
 
        }
    }
}

実行結果
3.03, 4.14, 5.25, 6.36

C#

Posted by arkgame