Andrei Rînea
Andrei Rînea

Reputation: 20790

Enumerate all possible characters

How can I enumerate all possible instances of System.Char ? I need to see for which ones System.Char.IsSymbol returns true, for example.

Upvotes: 2

Views: 1624

Answers (3)

Henrik
Henrik

Reputation: 23324

for (var c = System.Char.MinValue; c != char.MaxValue; ++c)
    DoSomething(c);
DoSomething(char.MaxValue);

Upvotes: 1

Bridge
Bridge

Reputation: 30701

Linq-y answer to give you the symbol characters:

var chars = Enumerable.Range(0, char.MaxValue+1)
                      .Select(i => (char) i)
                      .Where(c => char.IsSymbol(c))
                      .ToArray();

Credit really should go Sir Skeet, whose answer here it's based on.

Upvotes: 4

Justin Helgerson
Justin Helgerson

Reputation: 25551

for (int i = char.MinValue; i <= char.MaxValue; i++) {
    char c = Convert.ToChar(i);
    if (!char.IsSymbol(c)) {
        //kung-fu!
    }
}

Upvotes: 4

Related Questions