Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to convert?
Message
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01615029
Message ID:
01615074
Views:
32
>>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.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform