Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
158 views
in Technique[技术] by (71.8m points)

c# - 使用linq调用方法x次(Call method x times using linq)

I would like to call one method 3 times Using LINQ , the method returns an object, with that object I want to add it into a List, How do i do it?

(我想调用一个方法3次使用LINQ ,该方法返回一个对象,将该对象添加到列表中,该怎么做?)

List<News> lstNews = new List<News>();

lstNews.Add(CollectNews) [x 3 times] <-- Using Linq 

private static News CollectNews(){
...
}


  ask by Pablitros translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
var lstNews = Enumerable.Repeat(0, 3).Select(_ => CollectNews()).ToList();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...