I’ve got 2 LINQ-to-SQL lists and I merge them into 1 list using:
var mergedList = List1.Union(List2);
I assume that the Union command will eliminate all dupes in the list. Is that right? Anyway, I’m trying to write the contents of the merged list into a csv file. I’m getting errors when I try to call the list in:
WriteToCSVFile cf = new WriteToCSVFile(mergedList);
and this is how I constructed my class:
public WriteToCSVFile(IEnumerable<T> mergedList)
What am I doing wrong here?
Btw, this are the errors I’m getting:
The type arguments for method 'WriteToCSVFile.WriteToCSVFile(System.Collections.Generic.IEnumerable<T>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)
If you need more info, please let me know. And thanks in advance.
You need to make your class generic
and when calling it specify the generic argument type because generic types cannot be inferred from constructors:
Type inference works only with methods, so you could write an extension method:
and then:
Oh, and I sincerely hope that you are not rolling your own CSV parser, do you?