I have the following problem: I want to read workers data from a text file, which is formatted; worker_id;name;surname;login;
. And then write it to another file only containing lines without duplicate logins.
When I create class worker , List<workers>
and try this code:
List<worker> unics = workers
.GroupBy(w => w.login)
.Select(g => g.First())
.ToList();
Where string login = line1.Split(';')[3];
, everything is OK.
But when I use Lambdas without creating class worker (which is NOT necessary for me at the moment), it doesn't work.
List<string> unicsL = list1 //list1 - list of all lines1 in file
.GroupBy(x => x.Split(';')[3]) //ERROR - NullReferenceException // - Use new keyword to create object instance...
.Select(g => g.First())
.ToList();
What is the problem?