편집 : 공변량 제네릭은 아직 지원되지 않는 것으로 확인되었습니다. 다음 버전에서 확인하려면 Xamarin에 이메일을 보내이 기능을 요청하십시오.Monodroid 제네릭은 공분산하지 않습니까?
다음 코드는 오류를 발생시킵니다 (linq 문에서). 동일한 코드가 Microsoft clr C# 4.0에서 정상적으로 작동합니다.
오류 :
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<LinqTest.Person>' to 'System.Collections.Generic.IEnumerable<LinqTest.Entity>'. An explicit conversion exists (are you missing a cast?)
코드 : 내가 수정하거나 내가 뭔가를 놓친 거지
[Activity(Label = "LinqTest", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity {
protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle);
var names = new List<string> {
"Joe",
"Bob",
"Jim",
"Jane"
};
IEnumerable<Entity> query =
from e in names
select new Person() {Name = e};
SetContentView(Resource.Layout.Main);
var button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += delegate {
button.Text = string.Format("{0}", query.Count());
};
}
}
public class Entity {
public string Name { get; set; }
}
public class Person : Entity {
public string Workplace { get; set; }
}
public class Animal : Entity {
public string FurColour { get; set; }
}
건가요? 그렇다면 리팩토링에 대한 권장 사항은 무엇입니까?
또한, 그렇다면 공룡 제네릭 지원을위한 모노 도우미 지원에 대한 공식 기능 요청을 고려하십시오. :)
감사합니다.
감사합니다.이 기능을 사용하기를 기대합니다. – IUnknown