B
Bernhard Huemer
using System;
using System.Collections.Generic;
public class CovariantList<T> : List<T>
{
// ...
// of course this constraint won't work ..
public CovariantList<U> Convert<U>() where U: base T {
CovariantList<U> list =
new CovariantListList<U>(this.Capacity);
IEnumerator<T> enumerator = this.GetEnumerator();
while(enumerator.MoveNext()) {
list.Add(enumerator.Current);
}
return list;
}
// ...
}
I've been searching for a constraint to ensure following expression:
T t = /* .. */;
U u = t;
got the point ? if not consider following code:
public class CovariantList<T> : List<T>
{
// ...
// it's quiet plain to me that this overload is useless ..
public void Add<U>(U item) where U: T {
// now i'm able to write:
T t = item;
// how to do it the other way round ?
}
// ...
}
thanks
using System.Collections.Generic;
public class CovariantList<T> : List<T>
{
// ...
// of course this constraint won't work ..
public CovariantList<U> Convert<U>() where U: base T {
CovariantList<U> list =
new CovariantListList<U>(this.Capacity);
IEnumerator<T> enumerator = this.GetEnumerator();
while(enumerator.MoveNext()) {
list.Add(enumerator.Current);
}
return list;
}
// ...
}
I've been searching for a constraint to ensure following expression:
T t = /* .. */;
U u = t;
got the point ? if not consider following code:
public class CovariantList<T> : List<T>
{
// ...
// it's quiet plain to me that this overload is useless ..
public void Add<U>(U item) where U: T {
// now i'm able to write:
T t = item;
// how to do it the other way round ?
}
// ...
}
thanks