It is a lambda expression with vb.net syntax
So basically, when you have a list, array, or enumerable, you can add a period after it and it will list many functions that can be used with the list.
.Where() and .Select() are probably the most used, because .Where() let’s you pull in only certain values and .Select() let’s you massage or manipulate those values any way you would like. The result is always another list or array.
So going back to my example.
You get an array of filepaths by using directory.getdirectories("path")
—you can store this into another variable or just manipulate the array in one line like I have done for you.
When you add the .Select(), it essentially is going to go through each item in the array and perform the action on the value to get a new value for the array. Function(f) basically initializes the variable to be used and only used within the parenthesis of the function used (ie Select() or Where())… so “f” is a variable that represents each item within the array you are going through, and you can use any letter or word as the variable here.
So, when I place “f” inside the getfilename(), it is taking each filepath from the .getdirectories() array and pulling out only the filename or foldername to create a new array with the new values.
You can also take this further, given certain requirements, and filter the array:
directory.getdirectories("path").Select(Function(f) path.getfilename(f) ).Where(Function(f) f.StartsWith("abc") )
Which would return all foldernames that start with “abc”. So, there’s a lot you can do with this.
I hope my explanation was good enough for you to understand how it works.
In summary,
.Select(Function(variable) getfilename(variable) )
will go through each item in the list and change the value to only be the filename, which returns the desired array. And, remember that the variables used inside Function() does not need to be declared in variables and is only used within the parenthesis of that function, which means it can be used again if you use multiple functions in one line (but don’t use a variable name that is also declared in variables or there could be some conflicts.
Regards.