Hey All
Trying to figure out how to get the null coalescing operator to work in a foreach loop.
I'm checking to see what a string ends with and based on that, route it to a certain method. Basically what I want to say is....
foreach (String s in strList)
{
if s.EndsWith("d") ?? Method1(s) ?? Method2(s) ?? "Unknown file type";
}
In attempting to do this, of course you get the "Operator ?? cannot be used on type bool and type string." I know there is other ways to do it, just want to see how it can be done with null coalescing.
Have a good weekend.
@Richard Ev: Oh yes of course. Switch, if else, etc. Was just curious how it could be handled
@Jon Skeet: After reading your comments it hit me, this is just bad! I am interested in two file extensions basically. If a file ends with "abc" for instance, send to method 1, if the file ends with "xyz" send to method 2. But what if a file ends with an extension of "hij"...boom, you're done.
Thanks to Brian and GenericTypeTea as well for the thoughful input
I'm content calling it closed.