Interface IRealmCollection<T>
Iterable, sortable collection that is the base for all collections returned by Realm.
Inherited Members
Namespace: Realms
Assembly: Realm.dll
Syntax
public interface IRealmCollection<out T> : IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged
  Type Parameters
| Name | Description | 
|---|---|
| T | Type of the value contained in the collection.  | 
      
Properties
| Edit this page View SourceIsFrozen
Gets a value indicating whether this collection is frozen. Frozen collections are immutable and can be accessed from any thread. The objects read from a frozen collection will also be frozen.
Declaration
bool IsFrozen { get; }
  Property Value
| Type | Description | 
|---|---|
| bool | 
  | 
      
IsValid
Gets a value indicating whether this collection is still valid to use, i.e. the Realm instance hasn't been closed and, if it represents a to-many relationship, it's parent object hasn't been deleted.
Declaration
bool IsValid { get; }
  Property Value
| Type | Description | 
|---|---|
| bool | 
  | 
      
ObjectSchema
Gets the ObjectSchema, describing the persisted properties of the
IRealmObject or IEmbeddedObject instances
contained in the collection. If the collection contains primitive values, ObjectSchema will
be null.
Declaration
ObjectSchema? ObjectSchema { get; }
  Property Value
| Type | Description | 
|---|---|
| ObjectSchema | The schema of the objects contained in the collection.  | 
      
Realm
Gets the Realm instance this collection belongs to.
Declaration
Realm Realm { get; }
  Property Value
| Type | Description | 
|---|---|
| Realm | The Realm instance this collection belongs to.  | 
      
Methods
| Edit this page View SourceContains(object?)
Determines whether an element is in the IRealmCollection<T>.
Declaration
bool Contains(object? item)
  Parameters
| Type | Name | Description | 
|---|---|---|
| object | item | The object to locate in the IRealmCollection<T>.  | 
      
Returns
| Type | Description | 
|---|---|
| bool | true if item is found in the IRealmCollection<T>; otherwise, false.  | 
      
Freeze()
Creates a frozen snapshot of this collection. The frozen copy can be read and queried from any thread.
Freezing a collection also creates a frozen Realm which has its own lifecycle, but if the live Realm that spawned the original collection is fully closed (i.e. all instances across all threads are closed), the frozen Realm and collection will be closed as well. Frozen collections can be queried as normal, but trying to mutate it in any way or attempting to register a listener will throw a RealmFrozenException. Note: Keeping a large number of frozen objects with different versions alive can have a negative impact on the filesize of the Realm. In order to avoid such a situation it is possible to set MaxNumberOfActiveVersions.Declaration
IRealmCollection<out T> Freeze()
  Returns
| Type | Description | 
|---|---|
| IRealmCollection<T> | A frozen copy of this collection.  | 
      
See Also
IndexOf(object?)
Searches for the specified object and returns the zero-based index of the first occurrence within the entire IRealmCollection<T>.
Declaration
int IndexOf(object? item)
  Parameters
| Type | Name | Description | 
|---|---|---|
| object | item | The object to locate in the IRealmCollection<T>.  | 
      
Returns
| Type | Description | 
|---|---|
| int | The zero-based index of the first occurrence of item within the entire IRealmCollection<T>, if found; otherwise, –1.  | 
      
SubscribeForNotifications(NotificationCallbackDelegate<T>, KeyPathsCollection?)
Register a callback to be invoked each time this IRealmCollection<T> changes.
Declaration
IDisposable SubscribeForNotifications(NotificationCallbackDelegate<out T> callback, KeyPathsCollection? keyPathCollection = null)
  Parameters
| Type | Name | Description | 
|---|---|---|
| NotificationCallbackDelegate<T> | callback | The callback to be invoked with the updated IRealmCollection<T>.  | 
      
| KeyPathsCollection | keyPathCollection | An optional collection of key paths that indicates which changes in properties should raise a notification.  | 
      
Returns
| Type | Description | 
|---|---|
| IDisposable | A subscription token. It must be kept alive for as long as you want to receive change notifications. To stop receiving notifications, call Dispose().  | 
      
Remarks
The callback will be asynchronously invoked with the initial IRealmCollection<T>, and then
called again after each write transaction which changes either any of the objects in the collection, or
which objects are in the collection. The changes parameter will
be null the first time the callback is invoked with the initial results. For each call after that,
it will contain information about which rows in the results were added, removed or modified.
When the collection contains realm objects, it is possible to pass an optional KeyPathsCollection, that indicates which changes in properties should raise a notification. If no KeyPathsCollection is passed, Full will be used, so changes to all top-level properties and 4 nested levels will raise a notification. See KeyPathsCollection for more information about how to build it.
If a write transaction did not modify any objects in this IRealmCollection<T>, the callback is not invoked at all.
At the time when the block is called, the IRealmCollection<T> object will be fully evaluated and up-to-date, and as long as you do not perform a write transaction on the same thread or explicitly call Refresh(), accessing it will never perform blocking work.
Notifications are delivered via the standard event loop, and so can't be delivered while the event loop is blocked by other activity. When notifications can't be delivered instantly, multiple notifications may be coalesced into a single notification. This can include the notification with the initial collection.