xamarin - Realm dotnet : get element by index from RealmResults

标签 xamarin realm realm-net

我正在使用 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()并使用此集合作为数据源是否足够最佳?

最佳答案

Realm-Xamarin docs说:

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/

相关文章:

ios - xamarin ios 将运行多长时间?

xamarin - `Xamarin.Insights.Initialize(string)' 已过时

ios - Realm 同步数据在应用程序重新安装时重置

ios - Realm 结果<T> 计数返回 nil

c# - 如何在 Realm 对象(更准确地说是 DateTime)中实现 Nullable 属性?

c# - realm.xamarin 抛出错误 : The method 'Contains' is not supported. 与 'Any' 相同

java - 有没有办法从 Windows 服务器生成 Realm.io 数据库?

xamarin - 将 Sinch 与 Xamarin 结合使用

c# - .net maui 中的自定义控件和渲染器会发生什么?

swift - 如何更新列表中的一对多内容?