[*] Kann ich einen Spannwesen in eine Span ? ReadOnlyspan in einen readOnlyspan ?
Kann ich einen ReadOnlyspan in einen ReadOnlyspan ? Frage. < /p>
Beispiel des Problems: < /p>
Code: Select all
class Animal { }
class Dog : Animal { }
void Main() {
Dog[] dogs = new Dog[10];
Span dogSpan = dogs.AsSpan(0, 10);
// CS0030 Cannot convert type 'System.Span' to 'System.Span'
Span animalSpan1 = (Span)dogSpan;
// CS0453 The type 'Dog' must be a non-nullable value type in order to use it as parameter 'TFrom' in the generic type or method 'MemoryMarshal.Cast(ReadOnlySpan)'
// CS0453 The type 'Animal' must be a non-nullable value type in order to use it as parameter 'TTo' in the generic type or method 'MemoryMarshal.Cast(ReadOnlySpan)'
Span animalSpan2 = MemoryMarshal.Cast(dogSpan);
}