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:05:32
 
 
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:
01581951
Vues:
61
This message has been marked as a message which has helped to the initial question of the thread.
>I never tried switch for character expression. Let me try that then.
>
>>Could you reformat it into a switch statement?
>>
>>Bill
>>
>>>Hi everybody,
>>>
>>>In VFP I would use CASE expression. Is there any way to simplify this code?
>>>
>>>
>>>     if (String.Equals(mkvp.Key, "PRI_KEY", StringComparison.OrdinalIgnoreCase))
>>>                           groupMember.PrimaryKey = Convert.ToInt32(mkvp.Value);
>>>
>>>                        if (String.Equals(mkvp.Key, "FIRST", StringComparison.OrdinalIgnoreCase))
>>>                           groupMember.FirstName = mkvp.Value;
>>>
>>>                        if (String.Equals(mkvp.Key, "LAST", StringComparison.OrdinalIgnoreCase))
>>>                           groupMember.LastName = mkvp.Value;
>>>
>>>                        if (String.Equals(mkvp.Key, "GstNo", StringComparison.OrdinalIgnoreCase))
>>>                           groupMember.GuestNo = Convert.ToInt64(mkvp.Value);
>>>
>>>                        if (String.Equals(mkvp.Key, "Notes", StringComparison.OrdinalIgnoreCase))
>>>                           groupMember.Notes = mkvp.Value;
Just convert your key and strings to upper or lower first if you want to keep the case insensitive comparisons.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform