我正在使用 Xamarin 和 Realm 作为数据库来实现 android RecycleView。 RecycleView需要通过索引访问数据源。有什么方法可以通过索引从 RealmResults 检索元素吗?我发现在 Realm java中只需调用realmResults.get(index)方法就可以实现。但显然Realm的dotnet实现没有这样的方法。
另外根据 Realm 文档:
Objects are not copied - you get a list of references to the matching objects, and you work directly with the original objects that match your query.
那么,仅在realmresults上调用.ToList()并使用此集合作为数据源是否足够最佳?
最佳答案
To extract a list of all users named John or Peter you would write:
var johnsAndPeters = realm.All<Person>().Where(p => p.FirstName == "John" || p.FirstName == "Peter"); var peopleList = johnsAndPeters.ToList();
The ToList call, in this example, fires off the query which maps straight to the Realm core.
Objects are not copied - you get a list of references to the matching objects, and you work directly with the original objects that match your query.
基本上可以,请调用 ToList()
你得到的本质是RealmResults<T>
在 Realm-Java 中。
关于xamarin - Realm dotnet : get element by index from RealmResults,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38593260/