private void basicCRUD(Realm realm)
        {
            showStatus("Perform basic Create/Read/Update/Delete (CRUD) operations...");

            // All writes must be wrapped in a transaction to facilitate safe multi threading
            realm.beginTransaction();

            // Add a person
            Person person = realm.createObject(typeof(Person));

            person.Id   = 1;
            person.Name = "Young Person";
            person.Age  = 14;

            // When the transaction is committed, all changes a synced to disk.
            realm.commitTransaction();

            // Find the first person (no query conditions) and read a field
            person = realm.@where(typeof(Person)).findFirst();
            showStatus(person.Name + ":" + person.Age);

            // Update person in a transaction
            realm.beginTransaction();
            person.Name = "Senior Person";
            person.Age  = 99;
            showStatus(person.Name + " got older: " + person.Age);
            realm.commitTransaction();

            // Delete all persons
            realm.beginTransaction();
            realm.allObjects(typeof(Person)).clear();
            realm.commitTransaction();
        }
        private string complexReadWrite()
        {
            string status = "\nPerforming complex Read/Write operation...";

            // Open the default realm. All threads must use it's own reference to the realm.
            // Those can not be transferred across threads.
            Realm realm = Realm.getInstance(this);

            // Add ten persons in one transaction
            realm.beginTransaction();
            Dog fido = realm.createObject(typeof(Dog));

            fido.Name = "fido";
            for (int i = 0; i < 10; i++)
            {
                Person person = realm.createObject(typeof(Person));
                person.Id   = i;
                person.Name = "Person no. " + i;
                person.Age  = i;
                person.Dog  = fido;

                // The field tempReference is annotated with @Ignore.
                // This means setTempReference sets the Person tempReference
                // field directly. The tempReference is NOT saved as part of
                // the RealmObject:
                person.TempReference = 42;

                for (int j = 0; j < i; j++)
                {
                    Cat cat = realm.createObject(typeof(Cat));
                    cat.Name = "Cat_" + j;
                    person.Cats.add(cat);
                }
            }
            realm.commitTransaction();

            // Implicit read transactions allow you to access your objects
            status += "\nNumber of persons: " + realm.allObjects(typeof(Person)).size();

            // Iterate over all objects
            foreach (Person pers in realm.allObjects(typeof(Person)))
            {
                string dogName;
                if (pers.Dog == null)
                {
                    dogName = "None";
                }
                else
                {
                    dogName = pers.Dog.Name;
                }
                status += "\n" + pers.Name + ":" + pers.Age + " : " + dogName + " : " + pers.Cats.size();

                // The field tempReference is annotated with @Ignore
                // Though we initially set its value to 42, it has
                // not been saved as part of the Person RealmObject:
                assert(pers.TempReference == 0);
            }

            // Sorting
            RealmResults <Person> sortedPersons = realm.allObjects(typeof(Person));

            sortedPersons.sort("age", false);
            assert(realm.allObjects(typeof(Person)).last().Name == sortedPersons.first().Name);
            status += "\nSorting " + sortedPersons.last().Name + " == " + realm.allObjects(typeof(Person)).first().Name;

            realm.close();
            return(status);
        }