R.Tanaka.Ichiro's Blog

主にC# な話題です

目次

Blog 利用状況

ニュース

何周目?

http://mag.autumn.org/Content.modf?id=20100726164321
C#のforeach文で、自分が何回目の繰り返しか知る方法

ほほーっ

Select が教えてくれる

んですね。

MSDN ライブラリーを確認すると、ちゃんと書いてあったんですね。

http://msdn.microsoft.com/ja-jp/library/system.linq.enumerable.select.aspx
Select メソッド(MSDN ライブラリー)

ということで試してみた!

new [] { "A", "B", "C" }.Select((a, b) => a + ":" + b).ToList().ForEach(Console.WriteLine);

実行結果

A:0
B:1
C:2

すげー

投稿日時 : 2010年7月27日 14:30

Feedback

# re: 何周目? 2010/07/28 16:22 trapemiya

配列操作に使ったりしますね。以下のコードは作成中のWPFカスタムコントロールのパン屑リストの一部です。

var list=lst.Select((b, i) => { if (i >= BreadCrumbList.Count()) lst[i].FadeInOut = FadeInOut.FadeOut; return lst[i]; }).ToList();

# re: 何周目? 2010/07/28 21:09 Gushwell

Where とか TakeWhile でもindex 受け取ることができますよ。

# re: 何周目? 2010/07/29 10:01 trapemiya

先の例だと、以下の方がスマートですけどね(苦笑
var list=lst.Select((b, i) => { if (i >= BreadCrumbList.Count()) b.FadeInOut = FadeInOut.FadeOut; return b; }).ToList();

# 何周目?(その2) 2010/07/29 14:15 R.Tanaka.Ichiro's Blog

何周目?(その2)

# re: 何周目? 2010/07/29 14:16 R・田中一郎

むぅ・・・まったくもって知らなかったですorz

# re: 何周目? 2010/07/30 21:23 渋木宏明

ForEach のためだけに ToList()するのやだー
Rx 入れようよ。

# re: 何周目? 2010/08/02 10:45 trapemiya

Rxはまだよくわかんないですけど良さげですね。

# re: 何周目? 2010/08/02 14:18 R・田中一郎

Rxって何だろうと思って調べてみたら、車の情報ばっかり出てきた。

# Hello! This is kind of off topic but I need some help from an established blog. Is it very difficult to set up your own blog? I'm not very techincal but I can figure things out pretty quick. I'm thinking about setting up my own but I'm not sure where to 2019/11/26 6:34 Hello! This is kind of off topic but I need some h

Hello! This is kind of off topic but I need some help from an established blog.

Is it very difficult to set up your own blog? I'm
not very techincal but I can figure things out pretty quick.
I'm thinking about setting up my own but I'm not sure where to start.
Do you have any ideas or suggestions? With thanks

# Hello! This is kind of off topic but I need some help from an established blog. Is it very difficult to set up your own blog? I'm not very techincal but I can figure things out pretty quick. I'm thinking about setting up my own but I'm not sure where to 2019/11/26 6:35 Hello! This is kind of off topic but I need some h

Hello! This is kind of off topic but I need some help from an established blog.

Is it very difficult to set up your own blog? I'm
not very techincal but I can figure things out pretty quick.
I'm thinking about setting up my own but I'm not sure where to start.
Do you have any ideas or suggestions? With thanks

# Hello! This is kind of off topic but I need some help from an established blog. Is it very difficult to set up your own blog? I'm not very techincal but I can figure things out pretty quick. I'm thinking about setting up my own but I'm not sure where to 2019/11/26 6:36 Hello! This is kind of off topic but I need some h

Hello! This is kind of off topic but I need some help from an established blog.

Is it very difficult to set up your own blog? I'm
not very techincal but I can figure things out pretty quick.
I'm thinking about setting up my own but I'm not sure where to start.
Do you have any ideas or suggestions? With thanks

# Hello! This is kind of off topic but I need some help from an established blog. Is it very difficult to set up your own blog? I'm not very techincal but I can figure things out pretty quick. I'm thinking about setting up my own but I'm not sure where to 2019/11/26 6:37 Hello! This is kind of off topic but I need some h

Hello! This is kind of off topic but I need some help from an established blog.

Is it very difficult to set up your own blog? I'm
not very techincal but I can figure things out pretty quick.
I'm thinking about setting up my own but I'm not sure where to start.
Do you have any ideas or suggestions? With thanks

# all the time i used to read smaller posts which as well clear their motive, and that is also happening with this paragraph which I am reading here. 2019/12/30 23:54 all the time i used to read smaller posts which as

all the time i used to read smaller posts which as well clear their motive,
and that is also happening with this paragraph which I am reading here.

# 9 They will make Investigators probing the 4 2020/01/01 7:08 Typicalcat63

http://www.espace-emploi.fr/%ef%bb%bfmost-used-senior-online-dating-site-completely-free/ cheapest dating online site for 50 and older http://yamyapp.com/absolutely-free-biggest-mature-dating-online-site-blogs.wankuma.com.pdf most used senior dating online services free

# Appreciation to my father who stated to me about this webpage, this website is in fact remarkable. 2020/01/07 21:10 Appreciation to my father who stated to me about t

Appreciation to my father who stated to me about this webpage, this website is in fact remarkable.

# Appreciation to my father who stated to me about this webpage, this website is in fact remarkable. 2020/01/07 21:11 Appreciation to my father who stated to me about t

Appreciation to my father who stated to me about this webpage, this website is in fact remarkable.

# Appreciation to my father who stated to me about this webpage, this website is in fact remarkable. 2020/01/07 21:12 Appreciation to my father who stated to me about t

Appreciation to my father who stated to me about this webpage, this website is in fact remarkable.

# Appreciation to my father who stated to me about this webpage, this website is in fact remarkable. 2020/01/07 21:13 Appreciation to my father who stated to me about t

Appreciation to my father who stated to me about this webpage, this website is in fact remarkable.

# Hello there! I know this is kinda off topic however I'd figured I'd ask. Would you be interested in exchanging links or maybe guest authoring a blog post or vice-versa? My website goes over a lot of the same subjects as yours and I believe we could gre 2020/01/29 15:30 Hello there! I know this is kinda off topic howeve

Hello there! I know this is kinda off topic however I'd figured I'd ask.
Would you be interested in exchanging links or maybe guest authoring a blog post or vice-versa?
My website goes over a lot of the same subjects as yours and I believe we could greatly
benefit from each other. If you are interested feel free to shoot me an e-mail.
I look forward to hearing from you! Wonderful blog by the
way!

タイトル  
名前  
Url
コメント