In C# how can i use the || operand in an if statement where im looking for 2 files? -
i'm getting error "operator '||' cannot applied operands of type 'bool' , 'string'" when use below statement.
if (file.exists(@"c:\file1.exe") || (@"c:\file2.exe")) { }
how can this?
thanks
you had it...
if (file.exists(@"c:\file1.exe") || file.exists(@"c:\file2.exe")) { //do }
in if
statement, if want use ||
need make sure treat them separate pieces of statement.
in case, compiler have no way "guess" wanting know if file exists on right-hand statement, need explicit it.
just if want check see if person's age less 20 greater 18, following:
if (age < 20 && age > 18) {}
you can't age < 20 || 18
because talking anything, not age. if wanted weight or height second check? c# won't able guess you.
Comments
Post a Comment