list

Is it possible to automatically handle List.Contains by comparing a property on the item?

Can we do something similar to List.Contains(myItem) in order to check if a property on an item in the list equals a property on myItem. (We have considered Contains and Exists, something like: if (orderLines.Contains(myLine)) { ... } but cannot get a simple expression.) We would like something as simple as the following: if (ord...

Sorting dropdown list using Javascript

Hi, i want to sort the drop down items using javascript,can anyone tell me how to do this. ...

The whole If prevValue != currValue thing in a loop

Say we have a list {a, a, a, b, b, c, c } We want to loop through the list and make some kind of change when the item value changes... for example: prevEmployer = String.empty; foreach(Person p in PersonList){ if(p.Employer != prevEmployer){ doSomething(); prevEmployer = p.Employer; } ... more code } Is there any alt...

Best string container: StringCollection, Collection<string>, List<string>, ArrayList, .. ?

What is the most suitable container just for strings holding in some array with non-predetermined upper boundary, which length is unknown on it's creation. For simple code like: Foo list = new Foo(); // size in unknown for()/foreach()/do()/while() // any loop { list.Add(string); } Is it StringCollection as optimized Collection for ...

List<Rectangle> - behaves like there is a boxing

Hi We all know that generic List<> does not box value types. Why on the following code snippet the rects[1] is not affected by Inflate method? If there is no boxing and I want to afect the rect[1] I need to write three lines of code as it is shown - commented. Can someone please explain this? List<Rectangle> rects = new List<Rectangl...

stylish HTML list examples

Hi, I have a webpage that has a bunch of very boring HTML lists on it. I'm looking for some examples of ways to style these with CSS to make them look more interesting. So far I've only really found one, and would welcome some other examples. Thanks, Don ...

How to convert c++ std::list element to multimap iterator

Hello all, I have std::list<multimap<std::string,std::string>::iterator> > Now i have new element: multimap<std::string,std::string>::value_type aNewMmapValue("foo1","test") I want to avoid the need to set temp multimap and do insert to the new element just to get its iterator back so i could to push it back to the: std::list<m...

How to search a List(Of Byte) for two values using the Framework?

Is there a way of searching a list for more that one consecutive values? I've looking at Find and IndexOf but Find uses Predicates that only use the current value and IndexOf only takes byte parameters. I can code my own solution but I want to be sure that there isn't a solution already available to this common problem. Thanks in advan...

Python list.index question

Why does list.index throws an exception instead of returning a value like say -1? What's the idea behind this? To me it looks cleaner to deal with special values, etc than exceptions. EDIT: I didn't realize -1 to be usable, but in that case, how about a value of None? ...

All keys to a list, for example VK_A..Z for user to select

Hello All, I am making a program that allows user to custom keyboard shortcuts, for this i need the available keys to be displayed, what is the best way to achieve this in java swing? KeyEvent.class.getDeclaredFields() I am intrested in dynamic example of below, keysLST.setModel(new javax.swing.DefaultComboBoxModel(new String[]...

In Python 2.6, How Might You Pass a List Object to a Method Which Expects A List of Arguments?

I have a list full of various bits of information that I would like to pass to several strings for inclusion via the new string format method. As a toy example, let us define thelist = ['a', 'b', 'c'] I would like to do a print statement like print '{0} {2}'.format(thelist) and print '{1} {2}'.format(thelist) When I run this, I rece...

C# compare two Lists for differences

I would like some feedback on how we can best write a generic function that will enable two Lists to be compared. The Lists contain class objects and we would like to iterate through one list, looking for the same item in a second List and report any differences. We already have a method to compare classes, so we need feedback on how we...

Limit the size of List(Of T) - VB.NET

Hello I am trying to limit the size of my generic list so that after it contains a certain amount of values it wont add any more. I am trying to do this using the Capacity property of the List object but this does not seem to work. Dim slotDates As New List(Of Date) slotDates.Capacity = 7 How would people advice limi...

remove elements with specific value from std::list

I need to remove elements with specific value from std::list. With the list<int> I used remove() method. Now I have list<CMyClass> so I thought I should use remove_if() but it's predicate takes only one paramater - the element to be tested. How do I write a function foo(const CMyClass &Bad) which removes from list all the elements equa...

How can I convert a list<> to a multi-dimensional array?

I have the following method signature: public void MyFunction(Object[,] obj) I create this object: List<List<Object>> obj = new List<List<Object>>; Is there an easy way I can convert this to an Object[,]? UPDATE: The fact is I like to use Lists because I can easily add a new item. Is there a way I can declare my List<> object t...

How to implement a sharepoint lists webservice

I want to implement a web-service that uses the same interface as the Lists web service in sharepoint. I do not want to run this through sharepoint. What is a good way to get started in this? I have tried to use the wsdl.exe tool to generate some wrapper classes but the generated wrappers seem to have punted on the structure parameters ...

How do I define a generic std::list of a custom type?

I'm getting the following error trying to define a list of "Lines": line-clip.cpp:44: error: expected initializer before '<' token #include <list> using namespace std; class Line { public: Point p1; Point p2; Line(Point P1, Point P2) { p1 = P1; p2 = P2; } } // Line List list <Line> lineLi...

Whats the difference between list[-1:][0] and list[len(list)-1]?

Lest say you want the last element of a python list: what is the difference between myList[-1:][0] and myList[len(myList)-1] I thought there was no difference but then I tried this >>> list = [0] >>> list[-1:][0] 0 >>> list[-1:][0] += 1 >>> list [0] >>> list[len(list)-1] += 1 >>> list [1] I was a little surprised... ...

How can I get every nth item from a List<T>?

I'm using .NET 3.5 and would like to be able to obtain every nth item from a List. I'm not bothered as to whether it's achieved using a lambda expression or LINQ. Edit Looks like this question provoked quite a lot of debate (which is a good thing, right?). The main thing I've learnt is that when you think you know every way to do som...

Building a dictionary of counts of items in a list

I have a List containing a bunch of strings that can occur more than once. I would like to take this list and build a dictionary of the list items as the key and the count of their occurrences as the value. Example: List<string> stuff = new List<string>(); stuff.Add( "Peanut Butter" ); stuff.Add( "Jam" ); stuff.Add( "Food" ); stuff.Ad...