mercredi 26 septembre 2018

conditional ifs for multiple return cases

I have the following condition a class and a method

public class ReturnParameter
   {
      public string v1 {get; set;} 
      public string v2 {get; set;} 
      public string v3 {get; set;} 
   }


  public string RideCombination(ReturnParameter retor)
  {
     var v1 =  retor.v1;
     var v2 =  retor.v2;
     var v3 =  retor.v3;


     // case 1
     if(v1 == "A" && v2 == "b" && v3 == "C" ) 
       return  "valid 1 "

     // case 2
     if(v1 == "C" && v2 == "A" && v3 == "C" ) 
       return  "valid 2 "

    // case 3
     if(v1 == "D" && v2 == "T" && v3 == "C" ) 
       return  "valid 3 "

   // case 4
     if(v1 == "A" && v2 == "B" && v3 == "C" ) 
       return  "valid 4 "

  }

suppose I have 20 conditions I will have to 20 ifs to return 20 different combinations, is there any way I can eliminate multiple conditions without having to do one by one?

Aucun commentaire:

Enregistrer un commentaire