Let’s say i need to satisfy if condition based on multiple values.
For example, i would like to display some message limited to some users.
Let’s say i’ve {A,B,C,D,E,F} users
i would like to display Hello User for only {A,B,C} users
Normally we write if condition like
if(user == “A” || user ==”B” || user ==”C”)
{
<h2> Hello User </h2>
}
Instead we can write like this
if(new string[]{“A”,”B”,”C”}.Contains(user))
{
<h2> Hello User </h2>
{
<h2> Hello User </h2>
}
Here, we have mentioned all values inside a string collection and comparing string collection with input user.
If user value exists in string collection then if condition will get satisfied.
That’s it Folks!!!
If user value exists in string collection then if condition will get satisfied.
That’s it Folks!!!


0 comments:
Post a Comment
Note: only a member of this blog may post a comment.