Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is it possible to simplify this code?
Message
De
03/09/2013 15:17:17
 
 
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:
01581953
Vues:
64
>Hi everybody,
>In VFP I would use CASE expression. Is there any way to simplify this code?
    // I don't know the .NET syntax, but make a copy first with the upper-case conversion and do a test on the string
    String foo = mkvp.Key.ToUpperCase();
    
    // And put each entry in an else..if block, that way you're not testing all conditions every time
    if (foo.equals("PRI_KEY"))
       groupMember.PrimaryKey = Convert.ToInt32(mkvp.Value);
       
    else if (foo.equals("FIRST"))
       groupMember.FirstName = mkvp.Value;

    else if (foo.equals("LAST"))
       groupMember.LastName = mkvp.Value;

    else if (foo.equals("GSTNO"))
       groupMember.GuestNo = Convert.ToInt64(mkvp.Value);

    else if (foo.equals("NOTES"))
       groupMember.Notes = mkvp.Value;
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform