How to use the 'OR' Condition
-
Hi,this is my code.how to use OR condition in c# code,this code is not working.i want to check the selected image extension.if the extension .jpg or .bmp then it is going to this condition code.what is wrong in that. if (System.IO.Path.GetExtension(cmdBrowse.FileName).ToLower() != ".jpg" | System.IO.Path.GetExtension(cmdBrowse.FileName).ToLower() != ".bmp")
-
Hi,this is my code.how to use OR condition in c# code,this code is not working.i want to check the selected image extension.if the extension .jpg or .bmp then it is going to this condition code.what is wrong in that. if (System.IO.Path.GetExtension(cmdBrowse.FileName).ToLower() != ".jpg" | System.IO.Path.GetExtension(cmdBrowse.FileName).ToLower() != ".bmp")
Try
||
.. e.g.if (System.IO.Path.GetExtension(cmdBrowse.FileName).ToLower() != ".jpg" || System.IO.Path.GetExtension(cmdBrowse.FileName).ToLower() != ".bmp")
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
-
Hi,this is my code.how to use OR condition in c# code,this code is not working.i want to check the selected image extension.if the extension .jpg or .bmp then it is going to this condition code.what is wrong in that. if (System.IO.Path.GetExtension(cmdBrowse.FileName).ToLower() != ".jpg" | System.IO.Path.GetExtension(cmdBrowse.FileName).ToLower() != ".bmp")
Either || or | will work (although the non-short-circuiting single pipe is an odd choice here since it's more commonly used for bitwise or). Are you sure you don't want to test for equality rather than inequality? string lower = System.IO.Path.GetExtension(cmdBrowse.FileName).ToLower(); if (lower == ".jpg" || lower == ".bmp")
David Anton http://www.tangiblesoftwaresolutions.com C++ to C# Converter C++ to VB Converter C++ to Java Converter C++ to C++/CLI Converter Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: converts C# to C++/CLI and VB to C++/CLI
-
Hi,this is my code.how to use OR condition in c# code,this code is not working.i want to check the selected image extension.if the extension .jpg or .bmp then it is going to this condition code.what is wrong in that. if (System.IO.Path.GetExtension(cmdBrowse.FileName).ToLower() != ".jpg" | System.IO.Path.GetExtension(cmdBrowse.FileName).ToLower() != ".bmp")
I think u have to put 2 piping(||)characters in ur code It's like this.. if ((System.IO.Path.GetExtension(cmdBrowse.FileName).ToLower() != ".jpg") ||(System.IO.Path.GetExtension(cmdBrowse.FileName).ToLower() != ".bmp")) try this once...:)