collections

Binding a ObservableCollection<int> to IEnumerable<object> of a custom control

廉价感情. 提交于 2019-12-24 12:38:27
问题 With some help, I recently made binding collections in my custom control work. However, to my surprise I was told that to make the custom control property more flexible (that is possible to be bound with other parametrized collections), I needed to make the custom control's property to be of type IEnumerable<object> because of covariance and contravariance. However, this seems not to work for me This is the control's view <UserControl x:Class="BadaniaOperacyjne.Controls.Matrix" mc:Ignorable=

Sort list model with priority id's and date time

爱⌒轻易说出口 提交于 2019-12-24 12:27:24
问题 Sample List ArrayList<MyObject> list = new ArrayList<MyObject>(); list.add(new MyObject (1, "2011-04-27T09:40:01.607")); list.add(new MyObject (1, "2011-05-27T09:42:01.607")); list.add(new MyObject (2, "2011-06-27T09:42:01.607")); list.add(new MyObject (5, "2011-07-27T09:43:01.607")); list.add(new MyObject (6, "2011-08-27T09:44:01.607")); list.add(new MyObject (6, "2011-09-27T09:45:01.607")); list.add(new MyObject (1, "2011-10-27T09:46:01.607")); 1:-How to Sort ArrayList with the respect of

C# Compare Lists with custom object but ignore order

旧街凉风 提交于 2019-12-24 12:14:23
问题 I'm trying to compare 2 Lists (wrapped in an object) containing custom objects. I don't care about the order, but if list 1 contains "1,2,3,4" then list 2 must and only contain those elements. E.g.: "4,2,3,1" Based on Compare two List<T> objects for equality, ignoring order ignoring-order I've used the Except and Any but it doesn't give me the desired results. If I use Assert.Equals it fails, but Assert.IsTry(list1.equals(list2)) succeeds. Further more if I remove the Equals and GetHashCode

return LINQ Query result in IList and read it another class [duplicate]

此生再无相见时 提交于 2019-12-24 11:44:51
问题 This question already has answers here : Working with C# Anonymous Types (8 answers) Closed 5 years ago . I am using ASP.NET mvc 5. I have one class that holds all the LINQ which can access to another class. now i convert the LINQ query to list variable Query and returning as IList... the i create object of this class--> call the method and get result. now i can see in debugging object names but i can't see in foreach loop. my list hold mix data types, plus result is merging from different

Java sort a Hashmap on Value

不羁的心 提交于 2019-12-24 11:36:31
问题 Learning Java as I go (Python background). Simple word count program in Java 7 code (can not use J8!). I have a hash map of word:count pairs. Now I need to sort on count (decreasing order), and break ties with using word in alphabetical order. Have read s/o and I tried a treemap but it does not seem to handle ties very well so I don't think that is right. I have seen a lot of solutions posted that define a new class sortbyvalue and define a comparator. These will not work for me as I need to

Does AutoMapper's convention based mappings work with LINQ extension methods?

守給你的承諾、 提交于 2019-12-24 11:29:32
问题 I apologize if this is a duplicate but I did not find anything that seemed to be matching up with what I am looking for. As we all know in Automapper we can perform convention based mappings... My Question Is it possible to access extension methods (LINQ.First()) on objects in a collection, to go "n" levels deep? See example below My Entities public class Store { public IList< Departments > Departments {get;set;} } public class Departments { public bool Open {get;set;} } What I want to be

Get Jekyll collection item name (HRU)

大城市里の小女人 提交于 2019-12-24 11:27:28
问题 I'm making a Jekyll site destinated for GitHub Pages, and pre-testing it on local Windows 8.1 PC with Jekyll 2.5.3, Ruby 2.0.0p598 (2014-11-13) [x64-mingw32] and Gem 2.0.14. In Jekyll, I have a collection named albums . Directory structure for _albums is similar to the following: _albums foo.md bar.md baz.md Each file has Front Matter containing values such as title , description etc. In some site page I'm making a Liquid loop such as following: {% for album in site.albums %} /* need to get

Check if two collections are equal [duplicate]

旧街凉风 提交于 2019-12-24 10:59:08
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Is there a built-in method to compare collections in C#? Comparing two collections for equality I have tow collections that i want to check to see if the values contained within are not eqaul. SearchResultCollection Users1 = ds1.FindAll(); SearchResultCollection Users2 = ds2.FindAll(); Next i use 2 foreach loops to iterate through and then assign the variables. foreach (SearchResult users in Users1) { string

OrderedDict KeyError

好久不见. 提交于 2019-12-24 10:57:06
问题 import collections d = collections.defaultdict(dict) d["i"]["a"] = "111" d["i"]["b"] = "222" print d od = collections.OrderedDict() od["i"]["a"] = "111" od["i"]["b"] = "222" print od Output: defaultdict(<type 'dict'>, {'i': {'a': '111', 'b': '222'}}) Traceback (most recent call last): File "app_main.py", line 51, in run_toplevel File "/Users/adam/Desktop/collections.py", line 12, in <module> od["i"]["a"] = "111" KeyError: 'i' Why the key error with OrderedDict and what I can do about it?

Sorting set of string numbers in java

南楼画角 提交于 2019-12-24 10:42:15
问题 I need to sort a Set of String's which holds number. Ex: [15, 13, 14, 11, 12, 3, 2, 1, 10, 7, 6, 5, 4, 9, 8] . I need to sort it to [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] . But when i use Collections.sort(keyList); where keyList is Set, the reult i obtained is [1, 10, 11, 12, 13, 14, 15, 2, 3, 4, 5, 6, 7, 8, 9] . Please help. 回答1: Write a custom comparator and parse it as argument to Collections.sort(Collection,Comparator) . One solution is parsing your Strings to Integers.