Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is it possible to simplify this code?
Message
De
20/09/2013 09:35:00
 
 
À
20/09/2013 07:24:25
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:
01583718
Vues:
41
>>Good idea
>
>You can even put the whole treatment in GroupMember
>
>	class GroupMember
>	{
>		public int PrimaryKey;
>		public string FirstName;
>		public string LastName;
>		public long GuestNo;
>		public string Notes;
>
>		public GroupMember(int primaryKey, string firstName, string lastName, long guestNo, string notes)
>		{
>			PrimaryKey = primaryKey;
>			FirstName = firstName;
>			LastName = lastName;
>			GuestNo = guestNo;
>			Notes = notes;
>		}
>		internal void DoWork(MKVP mkvp)
>		{
>			new Switch()
>			   .Case(() => mkvp.Key == "FIRST", delegate {FirstName = mkvp.Value; })
>			   .Case(() => mkvp.Key == "LAST", delegate { LastName = mkvp.Value; })
>			   .Default(delegate { throw new Exception("No otherwise/default"); })
>			   .Execute();
>		}
>		
>	}
>	static class Test_Switch
>	{
>		internal static void Go()
>		{
>			GroupMember groupMember = new GroupMember(1, "Gregory", "Adam", 234, "none");
>			MKVP mkvp = new MKVP("LAST", "Alan");
>
>			groupMember.DoWork(mkvp);
>
>			Console.WriteLine("{0} {1} ", groupMember.FirstName, groupMember.LastName);
>		}
>	}
>
I like that best - cleaner because everything encapsulated within the class.....
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform