I have an IEnumerable and I want to use a linq statement to serialize each object in the IEnumerable and return another list. Here's my foreach I have:
List<EventData> payloads = new List<EventData>();
foreach (var request in requestList)
{
string message = JsonConvert.SerializeObject(request);
EventData data = new EventData(Encoding.UTF8.GetBytes(message));
payloads.Add(data);
}
I was attempting to do a Select statement like this:
requestList.Select(request => { JsonConvert.SerializeObject(request); });
Error message is :
The type arguments for method 'Enumerable.Select<TSource, TResult>(IEnumerable, Func<TSource, TResult>)' cannot be inferred from the usage. Try specifying the type arguments explicitly
The type arguments for method 'Enumerable.Select<TSource, TResult>(IEnumerable<TSource>, Func<TSource, TResult>)' cannot be inferred from the usage. Try specifying the type arguments explicitly
– DannyDvar list = requestList.Select(request => new EventData(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(request)))).ToList();
– 15ee8f99-57ff-4f92-890c-b56153requestList
? – John WurequestList
is aList<Request>
, it would simply be namedrequests
. – Rufus L