Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to convert?
Message
De
10/02/2015 11:10:49
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01615029
Message ID:
01615101
Vues:
33
This message has been marked as a message which has helped to the initial question of the thread.
>>>UPDATE. This compiles
>>>
>>>Select(val=>new KeyValuePair<string, string> (val.ListItemValue.ToString(), val.ListItemText)).ToList();
>>>
>>>Testing now.
>>>--------------------------------------------------------------------------------
>>>Hi everybody,
>>>
>>>I need to have List of KeyValuePair as a result.
>>>
>>>This is my current code
>>>
>>>typeCriteria.PossibleValues = EnumUtilities.EnumToEnumViewModel<TemplateTypes>(selectEnumValue: TemplateTypes.Pass, omitEnumValue: TemplateTypes.NotSpecified);
>>>
>>>and this is the error I am getting:
>>>
>>>Error	1	Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<SysManager.Common.Models.EnumViewModel>' to 'System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<string,string>>'. An explicit conversion exists (are you missing a cast?)	c:\_siriusware\main\sysmanager\sysmanager.web\areas\items\controllers\templatesapicontroller.cs	73	47	SysManager.Web
>>>
>>>
>>>where EnumViewModel is
>>>
>>>public class EnumViewModel
>>>    {
>>>        public virtual bool Selected { get; set; }
>>>        public virtual string ListItemText { get; set; }
>>>        public virtual Int32 ListItemValue { get; set; }
>>>    }
>>>
>>>How can I fix the syntax above to get List of KeyValuePair?
>>>
>>>Thanks a lot in advance.
>>
>>The obvious question : what would be the key and what would be the value...
>>
>>UPDATE: Assuming, for example, that ListItemValue should be the key and EnumViewModel itself the value:
List<KeyValuePair<Int32, EnumViewModel>> result =
>>                list.ConvertAll(x => new KeyValuePair<int, EnumViewModel>(x.ListItemValue, x));
>
>Thanks. I used the syntax I posted above and it also worked. I needed KeyValuePair of string, string where the first is ListItemValue.ToString() and the second is ListItemText.

I think yours is more efficient :-}
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform