Lets say I have an array like this:
string [] Filelist = ...
I want to create an Linq result where each entry has it's position in the array like this:
var list = from f in Filelist select new { Index = (something), Filename = f};
Index to be 0 for the 1st item, 1 for the 2nd, etc.
What should I use for the expression Index= ?
LINQ does not have an IndexOf method. So to find out index of a specific item we need to use FindIndex as int index = List. FindIndex(your condition); 0.
You can update rows in a database by modifying member values of the objects associated with the LINQ to SQL Table<TEntity> collection and then submitting the changes to the database. LINQ to SQL translates your changes into the appropriate SQL UPDATE commands.
Yes it supports General Arrays, Generic Lists, XML, Databases and even flat files. The beauty of LINQ is uniformity.
LINQ can be used to query and transform strings and collections of strings. It can be especially useful with semi-structured data in text files. LINQ queries can be combined with traditional string functions and regular expressions. For example, you can use the String.
Don't use a query expression. Use the overload of Select
which passes you an index:
var list = FileList.Select((file, index) => new { Index=index, Filename=file });
string[] values = { "a", "b", "c" }; int i = 0; var t = (from v in values select new { Index = i++, Value = v}).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With