c# array.find

Started by
3 comments, last by jor1980 13 years, 6 months ago
Hi to all, i have created a class named subfileInfo:
 public class SubFileINfo    {       public string Name;       public UInt32 StartOffset;       public UInt32 Length;    }


and i have an arrary of subfileInfo
SubFileInfo[] SubFileArray;



now i need to find in my SubFileArray the subfilesinfo that has in their names the string contained in textbox1.text

I am trying to do this wit Array.find but i am very confused i don´t achive to do it, How can i search for the subfilesinfo which contains into their name the substring textbox1.text
Advertisement
I think this should work:

SubFileINfo info = Array.Find(SubFileArray, sfi => sfi.Name.Contains(textbox1.text));


The => syntex is called a lambda expression, you can google that for more info.

The MSDN page shows an example without lambda expressions, which might be easier to understand.
Quote:Original post by Gage64
I think this should work:

SubFileINfo info = Array.Find(SubFileArray, sfi => sfi.Name.Contains(textbox1.text));


The => syntex is called a lambda expression, you can google that for more info.

The MSDN page shows an example without lambda expressions, which might be easier to understand.


Thank´s for the help, i have another question, normally that will find more than one elementswhich have the substring textbox1.tex in their name, could i make the operation you wrote me saving the results into a FileInfo array?
Yes, replace Find() with FindAll(). It returns an array with the results.
Thank´s for all you have help me a lot

This topic is closed to new replies.

Advertisement