Other than stepping through the elements one by one, how do I compare two lists of strings for equality (in .NET 3.0):
This fails:
// Expected result.
List<string> expected = new List<string>();
expected.Add( "a" );
expected.Add( "b" );
expected.Add( "c" );
// Actual result
a...
I have the following code that splits a string on newlines and converts it to a Dictionary for further processing:
string[] splitProgram = program.Split(Environment.NewLine.ToCharArray());
short i = 0;
Dictionary<short, string> programDictionary = splitProgram.ToDictionary<short, string>((value) => i++);
What's...
I have used generic queue in C# collection and everyone says that it is better to use the object of System.Collection.Generic.Queue because of thread safety.
Please advise on the right decision to use Queue object, and how it is thread safe?
...
Example scenario:
Create two SynchronizedSets (s1 and s2)
Pass them to two threads (T1 and T2)
Start the threads
T1's run() :
while (forever)
s1.equals(s2)
T2's run() :
while (forever)
s2.equals(s1)
What happens?
- SynchronizedSet's equals acquires lock on itself
It computes the length of the param that's passed in an...
I am trying to map a domain model in NHibernate. The domain model is implemented with what I think is DDD style. The mapping works mostly but then when I try to use a collection filter on an a collection I get an exception which says: The collection was unreferenced.
I know the problem comes from how I've implemented the collection. My ...
normally with a hashtable I do:
if(!myHash.Contains(someId))
{
// insert to hash
}
If I have a List, how can I check using contains?
Right now I am just creating a hashtable of user id's, and checking that, but is there a way just using just the List?
...
What I have?
An object that is saved in a static variable and called whenever needed
This object interfaces with another application.
I have two collections (Generic Lists) in this object
Logs
And
"Data That Is PreFeteched" to be used later
Problem is when more than one person is trying to use this object (the object interfaces with...
I'm working on a collection class that I want to create an __eq__ method for. It's turning out to be more nuanced than I thought it would be and I've noticed several intricacies as far as how the built-in collection classes work.
What would really help me the most is a good example. Are there any pure Python implementations of an __eq...
Hi there, I'm was going to update are windows VB.net project to use Subsonic 2.2.1 from 2.0.3.0
I was testing 2.2.1 to make sure everything would update with no problems and guess
What
I have most for the data grid views bind to the subsonic generated collection and I can change the columns header text, I found with the test that I c...
I've been looking for a method that operates like Arrays.equals(a1, a2), but ignoring the element order. I haven't been able to find it in either Google Collections (something like Iterables.elementsEqual(), but that does account for ordering) and JUnit (assertEquals() obviously just calls equals() on the Collection, which depends on the...
Hi folks,
I have two ObservableCollection lists, that i want to unite. My naive approach was to use the Union - Method:
ObservableCollection<Point> unitedPoints = observableCollection1.Union(observableCollection2);
ObservableCollection1/2 are of type ObservableCollection too. But the Compiler throws the following error for this line:...
I am using C# and targeting the .NET Framework 3.5. I'm looking for a small, succinct and efficient piece of code to copy all of the items in a ListBox to a List<String> (Generic List).
At the moment I have something similar to the below code:
List<String> myOtherList = new List<String>();
// Populate our colCriteria ...
Given the following code setup:
public class Foo {
List<string> MyStrings { get; set; }
}
List<Foo> foos = GetListOfFoosFromSomewhere();
How do I get a list of all of the distinct strings in MyStrings across all of the Foo instances using LINQ? I feel like this should be easy, but can't quite figure it out.
string[] distinctMyStrin...
I need to know if the type of a property in a class is a generic collection (List, ObservableCollection) using the PropertyInfo class.
enter code here
foreach (PropertyInfo p in (o.GetType()).GetProperties())
{
if(p is Collection<T> ????? )
}
...
Hi, I'm currently trying to implement the use of regular expressions:
Regex reg_gameinfo = new Regex(@"PokerStars Game #(?<HID>[0-9]+):\s+(?:HORSE)? \(?(?<GAME>Hold'em|Razz|7 Card Stud|Omaha|Omaha Hi/Lo|Badugi) (?<LIMIT>No Limit|Limit|Pot Limit),? \(?(?<CURRENCYSIGN>\$|)?(?<SB>[.0-9]+)/\$?(?<BB>[.0-9]+) (?<CURRENCY>.*)\) - (...
I've created many Geodata objects (name,postalCode,lat,lon). Now I want to put them into a collection to search for different entries later.
Everything should happen objectOriented/in-memory, so there shouln't be a need for a relational database.
Such a Query looks like:
Find lat and lon by name or plz
Find objects between LAT1,L...
Let's say I want to create a collection class that is thread-safe by default.
Internally, the class has a protected List<T> property called Values.
For starters, it makes sense to have the class implement ICollection<T>. Some of this interface's members are quite easy to implement; for example, Count returns this.Values.Count.
But imp...
I am not sure if there is already a nomenclature for this, but for the sake of this question lets define two terms: peer implementation or nested implementation to illustrate how you implement collection classes in a data model that contains many parent/child entity relationships.
I use the term peer to describe the scenario where you i...
Hi guys, I'm having a bit of an issue with Nhibernate / Fluent NHibernate
I have a class that has a collection and a backing field, and methods for manipulating the collection like so:
Edit: I've added the virtual modifier to Children since I forgot to stick it in the example code below (it was 2 am)
public class MyClass
{
private...
I have a list element which is populated via a query, this is then run through a for loop which sends this list to the front end, a jsp and prints them.
Wanted to know if by calling the list.clear() outside the for loop, it will clear the list object, so will this lead to better memory management? or should one use the weakhashmap for ...