If I have a collection of objects through a 'has and belongs to many' association in Rails (e.g. the album 'summer photos' has a collection of photos), how can I arbitrarily change the order of the elements in that collection? For example, there is a default index that would yield @album.images[0] or .first. how would I go about ch...
Is there an idiomatic way to take a Set<K> and a Function<K,V>, and get a Map<K,V> live view? (i.e. the Map is backed by the Set and Function combo, and if e.g. an element is added to the Set, then the corresponding entry also exists in the Map).
(see e.g. Collections2.filter for more discussion on live views)
What if a live view is ...
I have an app that uses EF POCO for accessing data. Everything works great, yet there is one problem with unit testing. Imagine two related classes:
public class Brother
{
public virtual Sister Sister { get; set; }
}
public class Sister
{
public virtual ICollection<Brother> Brothers { get; set; }
}
The problem here is that if...
All,
Can anyone please let me know exactly what are the performance issues between the 2? The site : CodeRanch provides a brief overview of the internal calls that would be needed when using keySet() and get(). But it would be great if anyone can provide exact details about the flow when keySet() and get() methods are used. This would h...
I am getting this error when I converting Application level variable into Hashtable;
First In Global.aspx file I have store Hashtable into Application variable like that:
Hashtable htErrorDescription = new Hashtable();
htErrorDescription.Add("Error 1","General Error");
htErrorDescription.Add("Error 2","Service Error");
context.Applica...
Hi, I'm puzzled about arrays in C#.
I can't find any documentation on MSDN about for example the object double[].
I do find documentation about int, array, collections, ... but can't find out of what type double[] is. If I do double[] a = new double[10]; a.GetType(), I find that the type of a is System.Double[]
I believe that the type ...
I dont know what is the best way to check if my object in my list is the last created.
What would be the optimal method to do it ?
Should I get the last element in the list and check if my given element is the last ?
...
Hi,
The "jsch" based implementation works for me.
But it looks not modern one due to using Vector (old style Java collection).
I found that the other implementations are less popular and not documented.
Can you recommend implementation of SFTP library that he/she has good experience with it.
Thanks.
...
Hi All,
This question is asked many a time in this forum. I know solution for the problem. But I am curious to know why "Enumeration operation can not execute when a collection is modified"
List<string> list = new List<string>();
list.Add("a");
list.Add("b");
int[] array = new int[6] { 1, 2, 3, 4, 5,...
Using the Northwind schema as an example which collection interface would you use in the following circumstances.
.
Customer
Customer has a collection of Orders. For the purpose of this example the Orders collection is readonly.
Order
An Order has collection of OrderDetails. An OrderDetail can be added to the collection.
Employee
...
I have a collection of Calendar objects. Calendar has a property Id.
IEnumerable<Calendar> CalendarsToView;
I have another collection of Event Objects. Event objects have a property of CalendarId
IEnumerable<CalendarEvent> Events;
i want to filter the Events collection to only return events where the calendarId is in the Calendar...
I already tried ArrayList^ and VB6 gives me a 'Type mismatch' error. I don't see a C++/CLI 'Collection' or 'List'.
So what is the equivalent, if there is one?
...
i have:
IEnumerable<Foo> foolist
and i want to convert this to:
IEnumerable<Bar> barlist
is there a linq / lambda solution to move from one to the other
both objects (foo and bar) have simple properties that i am going to convert. for example:
bar.MyYear = foo.Year
they each have about 6 properties
...
How do I get the values of a Map in the way they were declared?
If map's contents are-
Key "Apple" - Value "3"
Key "Banana" - Value "4"
Key "Orange" - Value "8"
I don't want to get-
Key "Banana" - Value "4"
Key "Apple" - Value "3"
Key "Orange" - Value "8"
How do I iterate and get the declared order?
...
I am trying to split a collection into multiple collections while maintaining a sort I have on the collection. I have tried using the following extension method, but it breaks them incorrectly. Basically, if I was to look at the items in the collection, the order should be the same when compared to the broken up collections joined. He...
What's the standard way to get a typed, readonly empty list in C#, or is there one?
ETA: For those asking "why?": I have a virtual method that returns an IList (or rather, post-answers, an IEnumerable), and the default implementation is empty. Whatever the list returns should be readonly because writing to it would be a bug, and if some...
Look at the specification of the ReadOnlyCollection class, it does implements the IList interface, right.
The IList interface have Add/Update/Read methods, which we call it pre-conditions of the interface. Anywhere in my application if I have an IList I should be able to do all this kind of operations.
But what about if I return a Rea...
I have reached this far:
implicit def collectionExtras[A](xs: Iterable[A]) = new {
def zipWith[B, C, That](ys: Iterable[B])(f: (A, B) => C)(implicit cbf: CanBuildFrom[Iterable[A], C, That]) = {
val builder = cbf(xs.repr)
val (i, j) = (xs.iterator, ys.iterator)
while(i.hasNext && j.hasNext) {
builder += f(i.next, j.ne...
How to Store and retrieve 3,000,000+ words in Dynamically without using SQL..
Get a word form a document then check whether the word is available or not.
if available,
then increment it in corresponding document count...
if not available
i.e, New word then create a new column then increment the document count and put Zero
...
Can I define an array or a list from anonymous class?
like this:
persons = new ... []
{
new { ID = 1, Name = "Name1"},
new { ID = 2, Name = "Name2"}
}
...