Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Simplest syntax of converting List of one type to anothe
Message
De
21/12/2017 04:37:36
 
 
Information générale
Forum:
C#
Catégorie:
LINQ
Divers
Thread ID:
01656603
Message ID:
01656623
Vues:
40
>Hi everybody,
>
>I have a variable items which is List of ItemsList and I want to convert it to List of IGlink . These two classes have similar definitions with some slight differences.
>
>
>This is IGlink class:
>
>
>public int IglinkId { get; set; } // iglink_id (Primary key)
>        public int IGroupNo { get; set; } // i_group_no. FK to i_group
>        public string Department { get; set; } // department (length: 10). FK to items
>        public string Category { get; set; } // category (length: 10)
>        public string Item { get; set; } // item (length: 10)
>
>        // Foreign keys
>        public virtual IGroup IGroup { get; set; } // FK_i_glink_i_group
>        public virtual Items Items { get; set; } // FK_i_glink_items
>
>
>This is ItemsList class:
>
>
>public string Department { get; set; } // Department (length: 10)
>        public string Category { get; set; } // Category (length: 10)
>        public string Item { get; set; } // Item (length: 10)
>        public int DepartmeId { get; set; } // DepartmeId
>        public int CategoryId { get; set; } // CategoryId
>        public int ItemId { get; set; } // ItemId
>        public string Descrip { get; set; } // Descrip (length: 135)
>        public bool Hidden { get; set; } // Hidden
>
>
>So, I am only interested of using ItemId, Category, Department, Item properties.
>
>How can I quickly convert one into another? Using select new ?
>
>Thanks in advance.

For linq, yes, 'select new'
Or you could modify one of the object classes to perform an implicit (or explicit) conversion....
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform