Home > DeveloperSection > Forums > check for any item in string array?
David Miller

Total Post:30

Points:210
Posted on    December-21-2014 10:26 PM

 ASP.Net C#  Array 
Ratings:


 2 Reply(s)
 591  View(s)
Rate this:

static void Main(string[] args)

{

    if (args[0].ToUpper().Equals("DOWNLOADPOS"))

    {

        DownloadPOS();

    }

will run DownloadPOS(), if the first item in args is downloadpos, I would like to check against all the items in args?? please advise?

 

I was previously using:

 

//if (args.Contains(pos))

//{

//    DownloadPOS();

//}

but then wasnt sure how to sure the upper on it

 

thanks



Sanjay Sharma
Sanjay Sharma

Total Post:45

Points:315
Posted on    December-22-2014 5:09 AM

if (arg.Any(x => x.Equals("DOWNLOADPOS", StringComparison.OrdinalIgnoreCase)))

{

    DownloadPos();

}

If you need to support special cultures (e.g. Turkish), use StringComparison.InvariantCultureIgnoreCase instead of StringComparison.OrdinalIgnoreCase


Chintoo Semi

Total Post:135

Points:947
Posted on    December-22-2014 6:45 AM

You can use Linq, Enumerable.Any Method Method

var exist = args.Any(x => x.ToUpper().Equals("DOWNLOADPOS"));

if (exist)

{

    DownloadPOS();

}


Don't want to miss updates? Please click the below button!

Follow MindStick