Sign in to follow this  
jor1980

c# array.find

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this