How to improve this code with C #

Possible duplicate:
Is there an easier way to do this if the instruction in C #

I have this code:

while ((txtSource.Text[startPos].ToString() == " ") || (txtSource.Text[startPos].ToString() == ",") || (txtSource.Text[startPos].ToString() == "."))) { // do something } 

is there any way to do this, for example, for example:

 while (!txtSource.Text[startPos].ToString() in (" ",",",".")) 
+4
source share
4 answers
 while ((new char[] {' ', ',', '.'}).Contains(txtSource.Text[startPos])) 
+7
source

LINQ Any() for reference:

 string text = "some text"; char[] controlChars = { ' ', ',', '.' }; int index = 1; bool passed = controlChars.Any(c => c == text[index]); 
+5
source
 string[] SearchList = {" ",",","."}; while (SearchList.Contains(txtSource.Text[startPos].ToString() )) { // Do Something } 
+4
source
 private static bool IsStopChar(char c) { switch (c) { case ' ': case ',': case '.': return false; default: return true; } } //... while (!IsStopChar(txtSource.Text[startPos])) { //... } 

With this solution, you avoid iterating the collection, allocating memory, initializing, ... Case modification remains easy.

+4
source

All Articles