Help us understand the problem. What is going on with this article?

LINQメモ

More than 5 years have passed since last update.

たまにLINQのどの操作が何なのか混乱するのでメモ。

Program.cs
//ランダムの生成
var rand = new Random();

//0~99の乱数を100個集めたIEnumerable<int>を作る
var list = Enumerable.Range(0, 100).Select(x => rand.Next(100));

//それを結合して文字列として出力する
Console.WriteLine(string.Join(" ", list));


//標準入力から受け取ったものを' 'で分割、intに変換して10未満のものだけ、数が小さいものから選びList<int>にする
var arr = Console.ReadLine().Split(' ').Select(int.Parse).Where(x => x < 10).OrderBy(x => x).ToList();

//1個ずつ出力する
arr.ForEach(x => Console.Write(string.Format("{0} ", x)));

//最後の改行
Console.WriteLine();

Whereはフィルタ
Selectは射影
OrderByは選択する順番

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした