S
Stefan Hoffmann
hi,
as i'm farely new to C#, i have some problem of creating a shallow copy
of a class inherited of CollectionBase.
As far as i see, i just need to copy the CollectionBase.List using the
CopyTo method.
Here i'm stuck:
public class myCollection : System.Collections.CollectionBase
{
protected myCollection()
{
}
protected int Add(object value)
{
if (value != null)
return List.Add(value);
else
return -1;
}
protected void Insert(int index, object value)
{
if (value != null)
List.Insert(index, value);
}
protected object this[int index]
{
get
{
return List[index];
}
set
{
Insert(index,value);
}
}
public void CopyTo(Array array, int start)
{
List.CopyTo(array, start);
}
}
Using
myCollection originalCollection = new myCollection;
myCollection shallowCopy = new myCollection;
originalCollection.CopyTo(shallowCopy, 0);
won't work.
I need some clues...
mfG
--> stefan <--
as i'm farely new to C#, i have some problem of creating a shallow copy
of a class inherited of CollectionBase.
As far as i see, i just need to copy the CollectionBase.List using the
CopyTo method.
Here i'm stuck:
public class myCollection : System.Collections.CollectionBase
{
protected myCollection()
{
}
protected int Add(object value)
{
if (value != null)
return List.Add(value);
else
return -1;
}
protected void Insert(int index, object value)
{
if (value != null)
List.Insert(index, value);
}
protected object this[int index]
{
get
{
return List[index];
}
set
{
Insert(index,value);
}
}
public void CopyTo(Array array, int start)
{
List.CopyTo(array, start);
}
}
Using
myCollection originalCollection = new myCollection;
myCollection shallowCopy = new myCollection;
originalCollection.CopyTo(shallowCopy, 0);
won't work.
I need some clues...
mfG
--> stefan <--