Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...