jeudi 22 mars 2018

C# - Weird behaviour in if-statement

We have a weird situation in an if-statment. Maybe someone has a hint for us, why the code runs into the if statement even when one condition is true and one condition is false. We are using Visual Studio 2017 professional.

We have this code:

if (Path.GetExtension(oListItem.File.Name).Equals(string.Empty))
{
    throw new Exception("Keine Dateiendung vorhanden");
}    

oListItem.File.Name has this value: BRO_Sekisui_PVOH_ENG_01_01_2009_Celvol Polyvinyl Alcohol in Emulsion Polymerization _3198.pdf

It always goes into the if-statement, even if we add another condition to our if statement.

if (Path.GetExtension(oListItem.File.Name).Equals(string.Empty) && !oListItem.File.Name.ToLower().EndsWith(".pdf"))
{
    throw new Exception("Keine Dateiendung vorhanden");
}    

Does anybody see a logical reason for this behaviour? Thanks in advance for your help.

Aucun commentaire:

Enregistrer un commentaire