lundi 29 mai 2017

If and Else If instruction

I have a directory with doc files (name firstname) For example I have this

Doe John Doe Phil Doe Robert Poe Dameron

I have a listbox with all the persons from a database, I choose a name and I click ‘open file’

My piece of code :

       string fullname = Name + " " + Firstname; 

       string[] allFiles = Directory.GetFiles((Doc_Path));
       foreach (string file in allFiles)
       {
           if (file.Contains(fullname))
           {
               Process.Start(file);
               return;
           }
       // if it cant found fullname, try to open by Name only
           else if(file.Contains(Name)) 
           {
               Process.Start(file);
               return;
           }
       }

My problem :

If I choose Doe Robert it opens Doe John in all case, but it should stop at the first IF instruction

I don't understand even if its the basic of basics :/

Aucun commentaire:

Enregistrer un commentaire