dh-s
asked on
C# If Item is not in array
Hello,
What I want to be able to do, in C#, is not do something if the item is in an array.
I have a for loop going through a list of items, and it is modifying them. There are some of them that I don't want modified, and I have stored the text of them in a pre-defined array. What I want, is the for loop to go through the array of elements that I want modified, but if the text matches any of the items in another array that I have defined, to not do anything.
Is there any easy way to do this?
Thanks.
What I want to be able to do, in C#, is not do something if the item is in an array.
I have a for loop going through a list of items, and it is modifying them. There are some of them that I don't want modified, and I have stored the text of them in a pre-defined array. What I want, is the for loop to go through the array of elements that I want modified, but if the text matches any of the items in another array that I have defined, to not do anything.
Is there any easy way to do this?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
List<string> dontModify= new List<string>();
and then add each text string that shouldn't be modified to the List
dontModify.Add("nochange1"
dontModify.Add("nochange2"
then you can
struct Item {
public string someText;
};
Item myItem = new Item(); // you'll have to initialize it correctly, of course
if (dontModify.Contains(myIte