Tuple – Replacement to temporary Entity classes.
July 28, 2010 Leave a Comment
C# 4.0 has introduced Tuple to replace entity classes which we create for temporary purpose to store values when returning from any methods. In general practice, we create entity class containing some properties in it to store values which lets say we store from DAL to return to presentation layer. These classes sometimes are for temporary use and of no use except storing values. Tuple, is really useful to replace such classes. Examples of it are as below:
|
static void Main(string[] args) //It will give compilation error, as Tuple.Create method can only create upto 8 elements. //It will work because new Tuple<> can create 8 or more elements. //It can access with Item1, Item2, t.Rest.Item1.Item2, etc. //Console.WriteLine(t); |