Guys,
Is there a may to write an instance method that only operates on a collection of the class?
So for example say I have something like this:
class Foo
def collection_method
puts "I only work on a collection of Foo!"
end
end
@foos = []
5.times {@foos << Foo.new}
@foo = Foo.new
@foos.collection_method #=> I only w...
Is there a way in .NET that I can sort my collection when I do not know what types of objects at run time I will pass to this collection and also by avoiding Reflection.
any thoughts?
...
This post contains a lot of code, but I would really appreciate it if you took the some to read and understand it...and hopefully come up with a solution
Let's assume that I am structuring a network-game where the entities need to be drawn and some of them updated from the server accordingly.
The Drawable class is in charge of drawing ...
Hey, I have this code here:
ArrayList arrayList = new ArrayList();
arrayList.add("one");
arrayList.add("two");
arrayList.add("three");
List<DataRow> dataList = GetDataList(some params);
Now I want to check if arrayList contains ther elements from dataList. The string is at itemarray[0] in dataList. Is there a nice short code version ...
I have a class with a collection member. I would like to prevent external code from modifying this collection directly, instead using methods (which can perform the appropriate validation etc).
This is harder than I thought. Here is the solution I am using. Can you please tell me if there are better ways to do this common thing? It all ...
Originally i wanted to ask for the fastest way to query a Datatable for a special row.
I have tested 5 different methods for their performance with a surprising(for me) result.
Background:
I have created a View in a MS Sql-Server 2005 Database. This view has current a total count of 6318 rows. Because i must check very often if a given...
Hi all
My domain classes have collections that look like this:
private List<Foo> _foos = new List<Foo>();
public virtual ReadOnlyCollection<Foo> Foos { get { return _foos.AsReadOnly(); } }
This gives me readonly collections that can be modified from within the class (i.e. by using the field _foos).
This collection is mapped as follo...
I would like to create a data structure or collection which will have O(1) complexity in adding, removing and calculating no. of elements. How am I supposed to start?
I have thought of a solution: I will use a Hashtable and for each key / value pair inserted, I will have only one hash code, that is: my hash code algorithm will generate ...
In Scala, for many (all?) types of collections you can create views.
What exactly is a view and for which purposes are views useful?
...
I need to map a collection of components with compass (using XML mapping)... Is there any way to achieve this?
Thanks in advance for any suggestions.
Example classes:
class ClassA {
private Set<ClassB> bs;
// ... getBs/setBs ...
}
class ClassB {}
Example mapping:
<class name="com.package.ClassA" alias="classA">
<!-- no ...
Hi,
I want to search in a Set without iterating manually over the elments but there does not seem to be a method to do Collections.search(myset, target, new ComparatorThing()). Am I not seeing something?
Thanks.
Edit:
I am searching for another field than the natural order of the elements.
As a manual workaround I used the following...
Hi guys,
I'm still learning VBA and I can't figure out wth I'm having so many problems with a Collections object.
I have a function that adds custom objects (I created a very simple class to store some data) that does the typical "read data, create object representation, stick it into Collections" sort of stuff.
If I try to add a "key...
Is there a performance difference between getting the count of an array (for example in c#) vs storing the count of an array in a variable.
This is assuming that the count isn't changing.
I'm presuming the answer will that storing it in a variable will cost more memory and accessing it directly e.g. array.length will be slightly slower...
I would like to store data in Generic Dictionary with keys that match over Date Ranges.
For instance, I came up with the following idea
public class MyKey : IEquatable<MyKey>
{
public int Key { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public override int GetHashCode()
{
...
Hello All,
I realize this question could be boiled down to "Why is my code so slow?" but I'm hoping to get more out of that. Let me explain my code.
I have a class that implements INotifyPropertyChanged in order to do binding, and that class looks similar to this:
public class Employee : INotifyPropertyChanged
{
string...
Hi. I'm a beginner with MyBatis.
I just want to know how to insert a collection of objects from an instance of a class. Say I have a class User related to a Note in one-to-many relationship. I just like to mention that I built my schema using JPA 2 annotations via Hibernate's hbm2ddl. I'll add the key JPA annotations I used in the sampl...
I have code below that builds a collection and returns it sorted by a property
var appChanges = GetHistory().ToList();
return appChanges.OrderByDescending(r => r.Change.When);
i want this to only return a max of 50 items (or total if collection size is less than 50)
how can i do this in LINQ ?
...
I need a Dictionary whose key is an array of integers for example Dictionary<int[],string> or
Dictionary<List<int>,string>.
But I am quite surprised that the Equality method and hash code method is not defined for me. Is there any easy way to implement such a structure other than creating my own MyType: List<int> and to define all ne...
How do i go from (cast?, convert?):
IEnumerable<Square>
to
IEnumerable<Shape>
...
I have a class Foos:
public class Foos
{
public string TypeName;
public IEnumerable<int> IDs;
}
Is it possible to map it with AutoMapper to IList of Foo objects?
public class Foo
{
public string TypeName;
public int ID;
}
...