Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is it possible to simplify this code?
Message
De
28/05/2014 16:39:22
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01581943
Message ID:
01600841
Vues:
52
This message has been marked as a message which has helped to the initial question of the thread.
>>Could you reformat it into a switch statement?
>>
>>Bill
>>
>
>How about this case - is there a way to simplify? (In VFP it's case expression):
>
>
> Boolean isRedemptionValid = row.Field<Boolean>("IsRedemptionValid"),
>                        isDateValid = row.Field<Boolean>("IsDateValid"),
>                        isTimeValid = row.Field<Boolean>("IsTimeValid"),
>                        isDowValid = row.Field<Boolean>("IsDowValid");
>
>                    if (isRedemptionValid && isDateValid && isTimeValid && isDowValid)
>                        {
>                            availability = "Available for Redemption";
>                        }
>                    else
>                        if (!isRedemptionValid)
>                        {
>                            availability = "Not enough number of uses";
>                        }
>                        else
>                            if (!isDateValid)
>                            {
>                                availability = "Not available in the date range";
>                            }
>                            else
>                                if (!isTimeValid)
>                                {
>                                    availability = "Not available in the time range";
>                                }
>                                else
>                                {
>                                    availability = "Not available on that day of the week";
>                                }
I don't know whether or not there can be multiple reasons for unavailability and what should happen if there are, but this might be an idea:
DataRow row = new DataRow();
         string availability = "";
         Boolean isRedemptionValid = row.Field<Boolean>("IsRedemptionValid"),
                           isDateValid = row.Field<Boolean>("IsDateValid"),
                           isTimeValid = row.Field<Boolean>("IsTimeValid"),
                           isDowValid = row.Field<Boolean>("IsDowValid");

         if (isRedemptionValid && isDateValid && isTimeValid && isDowValid)
         {
            availability = "Available for Redemption";
         }
         else
         {
            if (!isRedemptionValid)
            {
               availability += "Not enough number of uses";
            }
            if (!isDateValid)
            {
               availability += "Not available in the date range";
            }
            if (!isTimeValid)
            {
               availability += "Not available in the time range";
            }
            if (!isDowValid)
            {
               availability += "Not available on that day of the week";
            }
         }
     
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform