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

Categories

I am reading a collection of strings (of GUID format) from excel and want to store them in database as collection of GUIDs. I am just wondering is there any clean way to convert List<string> to List<Guid> using Linq. I am not interested in looping through.

See Question&Answers more detail:os

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

1 Answer

Either LINQ:

List<Guid> guids = guidStrings.Select(Guid.Parse).ToList();

or List.ConvertAll which is a little bit more efficient because it knows the size:

List<Guid> guids = guidStrings.ConvertAll(Guid.Parse);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...