I have a list.
It's possible members (x123, y123, z123, a123, b123, c123).//123 is example This "mylist" may contain a member that starting with x, or may not. Also this is the same for y,z,a,b,c.
If contains a member starts with x:
//Formula Contains X
If Not Contains a member starts with x:
//Formula Not Contains X
//same as all of x,y,z,a,b,c. But unlike a foreach, I must place the formulas at checking time, not after.
How can I do that?
Python example code use str. startswith() to find it a string starts with some string in a list. In the example list of substrings has converted into a tuple using tuple(list) in order to return a boolean if str contains substrings found it.
if (myList. Contains(myString)) string element = myList. ElementAt(myList. IndexOf(myString));
List<T>. Contains(T) Method is used to check whether an element is in the List<T> or not.
Python String startswith() method returns True if a string starts with the specified prefix (string). If not, it returns False.
Checks if any items start with 'x' in your list:
bool result = mylist.Any(o => o.StartsWith("x"))
Checks if no items start with 'x' your list:
bool result = !mylist.Any(o => o.StartsWith("x"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With