Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
2 dictionary collections
Message
From
29/09/2016 09:54:33
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 5.0
OS:
Windows 10
Database:
MS SQL Server
Miscellaneous
Thread ID:
01641447
Message ID:
01641500
Views:
39
Likes (1)
>>Actually my idea was overkill. Since your key value is a string then the default comparer should work anyway. What was the problem with your original code? Simple working example:
static void Main(string[] args)
>>        {
>>            Dictionary<string, string> AssignedTrackingColumns = new Dictionary<string,string>();
>>            Dictionary<string, string> TrackingLookupOrderColumns = new Dictionary<string, string>();
>>
>>            TrackingLookupOrderColumns.Add("A", "One");
>>            TrackingLookupOrderColumns.Add("B", "Two");
>>            TrackingLookupOrderColumns.Add("C", "Three");
>>            TrackingLookupOrderColumns.Add("D", "Four");
>>
>>            AssignedTrackingColumns.Add("A", "One");
>>            AssignedTrackingColumns.Add("C", "Three");
>>
>>            var result = TrackingLookupOrderColumns.Except(AssignedTrackingColumns);
>>
>>            foreach (var x in result)
>>            {
>>                Console.WriteLine(string.Format("Key:{0} Value:{1}",x.Key,x.Value));
>>            }
>>            Console.ReadLine();
>>        }
>
>It gave me an error in compile time that it needs an explicit cast.
>
>My code was:
>
>
> private Dictionary<string, string> trackingLookupOrderColumns = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
>
>This in the API controller.
>
>In the ViewModel I have
>
>
>public Dictionary<string, string> AvailableTrackingColumns = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
>        public Dictionary<string, string> AssignedTrackingColumns = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
>
>
>And in the GetPrefs method of the API controller I was trying
>
> prefsRetailViewModel.AvailableTrackingColumns = this.trackingLookupOrderColumns.Except(prefsRetailViewModel.AssignedTrackingColumns);
>
>which gives me
>
>Severity	Code	Description	Project	File	Line	Suppression State
>Error	CS0266	Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>>' 
>to 'System.Collections.Generic.Dictionary<string, string>'. An explicit conversion exists (are you missing a cast?)	
>
>Do you see what is different in my code?
>
>UPDATE. Got this compiled this way
>
> prefsRetailViewModel.AvailableTrackingColumns = this.trackingLookupOrderColumns.Except(prefsRetailViewModel.AssignedTrackingColumns).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
Just about to suggest that before you updated :-}
Previous
Reply
Map
View

Click here to load this message in the networking platform