For declaration perspective the following is allowed
IList<string> list= new string[3];
list.Add("Apple");
list.Add("Manago");
list.Add("Grapes");
1)
It compiles fine,But runtime i am getting "Collection was of fixed size" error.
Ofcourse ,collection is dynamically grown by size,why did such declaration is accepted by...
IList<string> strList = new string[] { "Apple", "Mango", "Orange" };
IList<string> lst = new ReadOnlyCollection<string>(new[]{"Google",
"MSN","Yahoo"});
In both cases i can not use "Add()" method for adding new items.then almost both
declarations are same?
...
Can't i overload List's Add method ?
class ListDemo<T>:List<T>
{
public override T Add<T>(T value)
{
return base.Add(value);
}
}
I am receiving the following error :
1) Type parameter 'T' has the same name as the type parameter from outer type 'CollectionsExample.ListDemo
2) 'CollectionsExample.ListDemo.Add(T)...
I apologize in advance; this is a long question. I've tried to simplify as much as I can but it's still a bit more long-winded than I'd care to see.
In some legacy code, we've got a VB6 collection. This collection adds objects via the .Add method and removes them via the .Remove method. However, via tracing I can see that sometimes w...
import java.util.Collection;
import example.Event;
public interface Query
{
public boolean hasMore ();
public Collection<Event> getNext ( long count ) throws Exception;
}
This is the interface I have, which I want to implement.
The implementation is supposed to be like this:
import java.util.ArrayList;
import java.util.Col...
I need something like this:
$products = Products::getTable()->find(274);
foreach ($products->Categories->orderBy('title') as $category)
{
echo "{$category->title}<br />";
}
I know is it not possible, but... How can I do something like this without creating a Doctrine_Query?
Thanks.
...
This is rather interesting, I think. Consider following code, both the window.onload and body onload="" call the same function. However, the results are different. It appears to me that window.onload has a problem with collections. Here's the code:
<html>
<script type="text/javascript">
window.onload = getSpanElements();
function ge...
So I am looping through some objects and initializing a Dictionary> object.
So first I check if the key exists, if it does I will add to the List
If it doesn't, I will create a new key and new List
Is that the right logic?
I will have to do a:
new List<int>();
the first time I insert an item right?
i.e.:
if(myDic.ContainsKey(car....
I am doing this right now:
foreach(..)
{
if(myDic.ContainsKey(car.ID) && myDic[car.ID].Contains(car.MfgID))
{
// do something
}
}
I was wondering if I can perform the check, but check if it doesn't exist, and then just do a continue.
How would I do that? using a || or &&?
I cant' assume the key/value is there so I don't want it t...
I have a my custom collection derived from List(.MyItem.)
I want to trace if my collection is modified, how can I do that?
I am able to track Add Remove operations etc...by implement new definition of them but I don't see any method in List that gives me opportunity to track if collection is modified...
...
AssemblyInstaller.Install expects a System.Collections.IDictionary.
Am I right to be 'allergic' to using non-generic collections such as Hashtable or should I get over myself?!
e.g.
using System.Collections.Generic;
using System.Configuration.Install;
using System.Reflection;
using AssemblyWithInstaller;
namespace InstallerDemo
{
...
I need to write a generic class where the type parameter must be something implementing ICollection<T>. Inside of MyClass I need the collection's item type (in the code snippet marked as ???).
class MyClass<TCollection> where TCollection : ICollection<???>
{
// ...
public void store(??? obj) { /* put obj into collection */ }
// ...
I am new to C#.Working in ASP.NET 3.5 ( C# 3.0). What are the collection classes do i need to familiar with inorder to develop effective code ? like IList, and counterpart IList<T>,List,List<T> are enough ?
Thank you very much to all ,for giving me a very good guidance.
...
I have a bas class called Media with two classes that inherit from it, Photo and Video. I am trying to create a collection for the media base class to hold those photo and video objects. So I have created a MediaList class as follows:
public class MediaList: ICollection<Media>
{
private readonly XElement _mediaElement;
public M...
I have a form where users can modify a collection of objects using a DataGrid. When the form is opened I create a deep copy of the original collection and if the Cancel button is pressed I just discard that copy.
The problem is that when the OK button is pressed I have to reconcile the changes which might be:
Modified properties of ex...
I have two maps of type Map<Long, Integer>, one named "old" representing the old state of an object, and the other named "new" representing the new state of the same object.
Is there a simple & readable way of knowing if the old state and the new state are different (ie. if the state has changed)?
Ideally, I'd like some "java.utils" or...
Suppose class B extends class A. I have a List<A> that I happen to know only contains instances of B. Is there a way I can cast the List<A> to a List<B>?
It seems my only option is to iterate over the collection, casting one element at time, creating a new collection. This seems like an utter waste of resources given type erasure makes ...
Simple question.
I have a new list and an old list. In Java is there a standard way/library that allows me to compare these two lists and determine which items have been updated/deleted or are completely new? E.g. I should end up with three lists - Deleted items (items in old but not in new), Updated items (items in both), New items (it...
In Eclipse, I see that ArrayList objects have a modCount field. What is its purpose? (number of modifications?)
...
We have several areas where code like this can be seen
public Map extractData(ResultSet rs) throws SQLException, DataAccessException {
Map m = new HashMap();
while(rs.next()){
Jurisdiction j = new Jurisdiction();
m.put("code",rs.getLong(1) );
m.put("type",rs.getSt...