I'm stuck and I need help. Anyway I have Visual Studio 2008 console program that needs to log a Date, String, Boolean, and an integer for each round of a game. Say the user plays 10 rounds I would have 10 of each.
I want to save those records in a data structure (collection i believe) and then after the game is finished loop through th...
I am new to generics. I want to implement my own collection by deriving it from IList<T> interface.
Can you please provide me some link to a class that implements IList<T> interface or provide me a code that at least implements Add and Remove methods?
...
bool IsTypeAGenericList(Type listType)
{
typeof(IList<>).IsAssignableFrom(listType.GetGenericTypeDefinition())
}
returns false when given typeof(List<int>).
I assume this is because the two type parameters can be different, correct?
...
I need to add key/object pairs to a dictionary, but I of course need to first check if the key already exists otherwise I get a "key already exists in dictionary" error. The code below solves this but is clunky.
What is a more elegant way of doing this without making a string helper method like this?
using System;
using System.Collecti...
Say I have this class :
public class BaseJob{
String name;
public void setName(String name){
this.name=name;
}
public String getName()
{
return name;
}
}
and another class that extends it :
public class DetailedJob extends BaseJob{
public void doThing();
}
Furthermore, I have this method in another class :
List<BaseJob> ...
Hello,
I have a class "Employee", this has an IList<> of "TypeOfWork".
public class Employee
{
public virtual IList<TypeOfWork> TypeOfWorks { get; set; }
}
public class TypeOfWork
{
public virtual Customer Customer { get; set; }
public virtual Guid Id { get; set; }
public virtual string Name{ get; set; }
public vi...
When a user submits a form and leaves certain fields blank, they get saved as blank in the DB. I would like to iterate through the params[:user] collection (for example) and if a field is blank, set it to nil before updating attributes. I can't figure out how to do this though as the only way I know to iterate creates new objects:
col...
I have a partial that I want rendered with a collection and another variable. Is it possible to pass more than one variable to a partial?
To illustrate:
Category HABTM Brands
This is just semi-pseudo-code, but I want to do something like:
<% @categories.each do |c| %>
<%= c.name %>
<%= render :partial => "mypartial", :collec...
I currently have a menu with subitems that is being stored in this dictionary variable:
private Dictionary<string, UserControl> _leftSubMenuItems
= new Dictionary<string, UserControl>();
So I add views to the e.g. the "Customer" section like this:
_leftSubMenuItems.Add("customers", container.Resolve<EditCustomer>());
_leftSubMen...
I have a helper class that implements ITypedList, to provide objects for databinding against custom collections.
My implementation allows me to easily specify that I want sub-properties of objects to be available for data binding, for instance I can bind to "Id", "Name", and also "Children.Count".
Now, my problem now is that in order t...
I have a c# 3 HashSet object containing several elements. I want to check something between every pair of them, without repeating [(a,b)=(b,a)], and without pairing an element with itself.
I thought about switching to some sort of List, so I can pair each element with all of his following elements. Is there an option of doing something l...
I am having trouble figuring out the best way to approach this problem,
I have two different list of items,
one in the DB, one not. Both list have
item ids and quantity, I need to merge
the two list into the DB.
My first inclination is to just pull all of the items out of the DB then merge the two list in the application logi...
Possible Duplicate:
count vs length vs size in a collection
Am I overlooking a semantic difference between "Length" and "Count", or did perhaps some implementation detail in the .NET Framework require different names for these similar concepts? Given the close attention that was paid to naming and everything else in the framewor...
Had a system with v2 running well. Swapped out the Visual Studio reference for the v2 DLL to the v3 DLL. Rebuilt the project. Errors.
I used to have things called "MyYahooCollection", now I only have "MyYahoo" and "MyYahooTable". The collections seem to be gone.
What did I miss?
I am using SQL Server 2005 on the back-end and am imple...
I want to make a collection that stores groups of users. A user can be a member of multiple groups, groups can be nested, a selection of groups should return a distinct IEnumerable<user> .
I could write this from scratch of course using the standard List<T>,Dictionary<T,U> etc collections, but is there a built-in collection that already...
I have a number of methods in C# which return various collections which I wish to test. I would like to use as few test APIs as possible - performance is not important. A typical example is:
HashSet<string> actualSet = MyCreateSet();
string[] expectedArray = new string[]{"a", "c", "b"};
MyAssertAreEqual(expectedArray, actualSet);
//.....
If I have a simple list of Strings:
List<String> stringList = new ArrayList<String>();
I can sort it with:
Collections.sort(stringList);
But suppose I have a Person class:
public class Person
{
private String name;
private Integer age;
private String country;
}
And a list of it:
List<Person> personList = new ArrayList<...
I need to pass a list of Days (number and name) to an view!
Whats the best way to do this?
I was thinking of creating a generic collection, but not sure how? or an array?
...
(This is a variant to this Q&A)
Say I have this:
List( "foo", "bar", "spam" )
I want to create a Map for which the key is the length of the String and the value is a Collection of all the Strings that have that length. In other words, given the about List, we'd get:
Map( 3 -> List(foo, bar), 4 -> List(spam) )
The code I've written...
I have methods returning private collections to the caller and I want to prevent the caller from modifying the returned collections.
private readonly Foo[] foos;
public IEnumerable<Foo> GetFoos()
{
return this.foos;
}
At the moment the private collection is a fixed array, but in the future the collection might become a list if th...