Reputation: 47743
I can't figure out what could be static here to cause that error below:
public bool OptionsMatch(Item item, ItemFavorite itemFavorite)
{
bool isSame = true;
switch (item.DispType)
{
case DispType.Dropdown:
case DispType.Radio:
isSame = String.Contains(item.Value);
break;
case DispType.ImageList:
isSame = ListValuesMatch(item, itemFavorite);
break;
}
return isSame;
}
Error: Cannot access non-static method 'Contains' in static context
DispType is an enum. And the rest are all non-static concrete type instances as well as the underlying class is not static either that contains this method.
Upvotes: 0
Views: 781
Reputation: 1038890
Here's the problem which occurs:
isSame = String.Contains(item.Value);
Contains is an instance method:
isSame = "foo".Contains(item.Value);
or the other way around depending on what you are trying to do:
isSame = item.Value.Contains("foo");
Upvotes: 2
Reputation: 754763
The method Contains
on System.String
is an instance method. You're trying to access using the type System.String
which is an error. You'll need an instance of string.
Upvotes: 0
Reputation: 4209
String.Contains
is not a valid static method. What are you trying to evaluate?
Upvotes: 0
Reputation: 144122
string.Contains
is not static, it is an instance method; i.e. it is called on an instance of a string, like so:
"something".Contains(item.Value);
This is because Contains
requires two objects - the reference string, and the string to search for. You've only provided one (the string to search for) but not where to look.
Upvotes: 6