If you have Guid values in a string separated by a comma and want to convert all comma-separated GUIDs to a list of GUID then here is a single line code that will do the trick.
private List<Guid>
GetSelectedIdList(String selectedIds)
{
return Array.ConvertAll(selectedIds.Split(','), delegate(string s) { return new Guid(s); }).ToList();
}
|
Or you can rewrite the same method with the help of lambda expression as:
private List<Guid>
GetSelectedIdList(String selectedIds)
{
return Array.ConvertAll(selectedIds.Split(','), s => new Guid(s)).ToList();
}
|
Just pass
the comma separated string and “GetSelectedIdList” method will return list of
GUID.
private List DelimitedStringToListOfGuids(string value, char delimiter)
ReplyDelete{
List guids = new List();
value.Split(delimiter).ToList().ForEach(
delegate(string s)
{
Guid g = new Guid();
if (Guid.TryParse(s, out g))
guids.Add(g);
}
);
return guids;
}