tags:

views:

60

answers:

3

Instead of looping over my string I'd like to use LINQ. How to do the following?

//  explode our word
List<char> rackBag = new List<char>();
rackBag.AddRange("MYWORD??".ToCharArray());

// How many wildcards?
int wildCardCount = rackBag.Count(x => x.Equals("?"));

wildCardCount should equal 2.

+5  A: 
rackBag.Count(x => x == '?'); 
Vivek
Since `x` is a `char`, it isn't equal to the `string` value `"?"`
bdukes
+1  A: 

int wildCardCount = rackBag.Count(x => x=='?');

Vinay B R
+6  A: 

Lots of unneeded steps there. Try this:

int wildCardCount = "MYWORD??".Count(x => x == '?');
jball