Call Generic Method with Anonymous Type (C #)

Let me just say that I would like to iterate over the string[][] value, add the value using an anonymous type and execute the general ForEach-Extension method as a result (a vivid example, I know, but I suppose you will get it because of this! )

Here is my code:

 //attrs = some string[][] attrs.Select(item => new { name = HttpContext.GetGlobalResourceObject("Global", item[0].Remove(0, 7)), value = item[1] }) .ForEach</*????*/>(/*do stuff*/); 

What exactly would I have to enter in Type-Parameter forEach?

Here's what ForEach looks like:

 public static void ForEach<T>(this IEnumerable<T> collection, Action<T> act) { IEnumerator<T> enumerator = collection.GetEnumerator(); while (enumerator.MoveNext()) act(enumerator.Current); } 
+4
source share
1 answer

You do not need to explicitly specify the type, as it can be inferred from the following parameters:

 attrs.Select(item => new { name = HttpContext.GetGlobalResourceObject("Global", item[0].Remove(0, 7)), value = item[1] }) .ForEach(x => x.name = "something"); 
+8
source

All Articles