Click here to Skip to main content
14,828,868 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
string[] month = { "jan","feb","mar"}
if (s.Contains(month) && (s.Any(char.IsDigit)))
                    { 
                        //code here
                    }


What I have tried:

monthcode shows an error that Cannot implicitly convert type string[] to string'
Posted
Updated 2-Dec-20 3:53am
v4
Comments
PIEBALDconsult 2-Dec-20 8:58am
   
What s? What's monthCode?
john123a 2-Dec-20 9:11am
   
not month code its month.my bad
john123a 2-Dec-20 9:13am
   
i am splitting a string with space and foreach loop that word.so s represent each looped word
PIEBALDconsult 2-Dec-20 8:58am
   
And one should never post an e-mail address publicly.
john123a 2-Dec-20 9:11am
   
how should i hide email
BillWoodruff 2-Dec-20 9:41am
   
show the definition of 's

That is because you are asking if s (a String I presume) contains an array of strings. I think you likely have it backwards.
   
If "s" is a string then you want to check if the array contains the string, but your current code checks if the string contains the array. Change it to

C#
if (month.Contains(s) && (s.Any(char.IsDigit)))
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900