Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to improve this code using c# [duplicate]

Tags:

string

c#

Possible Duplicate:
Is there a simpler way to do this if statement 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 the above like for instance:

while (!txtSource.Text[startPos].ToString() in (" ",",","."))
like image 373
Somebody Avatar asked Dec 01 '22 05:12

Somebody


1 Answers

while ((new char[] {' ', ',', '.'}).Contains(txtSource.Text[startPos]))
like image 91
Steven Doggart Avatar answered Dec 05 '22 17:12

Steven Doggart