Initialisation de List<T> inline avec T = classe abstraite
Bonjour,
J'ai une classe abstraite "Value".
Code:
1 2 3 4 5
|
public abstract class Value
{
public abstract int CompareTo(Value other);
} |
Et des classes dérivées : "StringValue", "IntValue", etc.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
public class StringValue : Value
{
private string Value = string.Empty;
public StringValue(string Value)
{
this.Value = Value;
}
public override int CompareTo(Value other)
{
if (other == null)
{
return 1;
}
StringValue s = (other as StringValue);
if (s == null)
{
return 1;
}
else
{
return this.Value.CompareTo(s.Value);
}
}
}
public class IntValue : Value
{
private int Value = 0;
public IntValue(int Value)
{
this.Value = Value;
}
public override int CompareTo(Value other)
{
if (other == null)
{
return 1;
}
IntValue s = (other as IntValue);
if (s == null)
{
return 1;
}
else
{
return this.Value.CompareTo(s.Value);
}
}
}
} |
Je souhaite initialiser inline un List<Value> contenant donc une série d'instances des différentes classes dérivées :
Code:
1 2
|
List<Value> l1 = new List<Value>(new[] { new IntValue(1), new StringValue("sylvain"), new StringValue("lyon") }); |
Il me dit :
Citation:
No best type found for implicitly-typed array
J'ai raté quoi ?