I have following line of code which creates an list of strings.
List<string> tstIdss = model.Ids.Where(x => x.Contains(entityId)).Select(x => x.Split('_').First()).ToList();
I need to convert it into list of Guids. i.e. List<Guid> PermissionIds.
model.PermissionIds= Array.ConvertAll(tstIdss , x => Guid.Parse(x));
I tried the above way but getting the following error. model.PermissionIds
is implemented as following in my model class.
public List<Guid> PermissionIds { get; set; }
Error 3
>>The type arguments for method 'System.Array.ConvertAll<TInput,TOutput>(TInput[], System.Converter<TInput,TOutput>)'
cannot be inferred from the usage.
Try specifying the type arguments explicitly.
ConvertAll(tstIdss , x => Guid. Parse(x));
Pass the List<String> as a parameter to the constructor of a new ArrayList<Object> . List<Object> objectList = new ArrayList<Object>(stringList);
You can use Linq's Select
and ToList
methods:
model.PermissionIds = tstIdss.Select(Guid.Parse).ToList();
Or you can use the List<T>.ConvertAll
method:
model.PermissionIds = tstIdss.ConvertAll(Guid.Parse);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With