Find index of returned list result C#

As the error states, it cannot convert from 'System.Collections.Generic.List' to 'string'. However I never knew the function SingleOrDefult() existed.

All credit to @maccettura even though he didn't know what I was trying to do! xD

Code change below for the answer:

List<string> listFrom = new List<string>(); //Contains a list of strings
List<string> listTo = new List<string>(); //Contains a list of strings

string lineStart = listFrom.Except(listTo).SingleOrDefault();
string lineEnd = listFrom.Except(listTo).SingleOrDefault();

int startLineIndex = listFrom.IndexOf(lineStart);            //Error on this line
Console.WriteLine("Index of Start: " + startLineIndex);

Browse More Popular Posts

Leave a Comment