Using Visual Basic // C#
I\'m trying to search through my stored arrays for a match to the user input. For example, the user has stored the data for a USB, and now wish
You need using System.Linq;
for that to work.
Any is an extension method defined in LINQ.
Also, pay attention to the type of ProductNameArray
. If it is defined as Array
(and not string[]
, for example), the compiler has no way of inferring that, when enumerated, it'll yield string
s.
In that case, you'd have to write:
if (ProductNameArray.Cast<string>().Any(usersearch.Contains))
Edit: OK, looking at the code it seems that the problem is the one described above.
You'll have to change the signature of the FindProduct
method from
static void FindProduct(Array ProductNameArray)
to
static void FindProduct(string[] ProductNameArray)
or use the .Cast<string>
method.
I'd personally prefer changing the method's signature, since the ProductNameArray
passed to it seems to really be a string[]
.
Any()
is an extension method in System.Linq
namespace. You have to add using System.Linq;
so that you can use it.
namespace Your.Namespace
{
using System;
using ... // your other usings
using System.Linq;
public sealed class YourClass
{
public void Test()
{
// ...
yourArray.Any()
}
}
}
Add below to you code
using System.Linq;