This project is read-only.

Array Insert ? (SOLVED)

Apr 27, 2013 at 2:31 PM
I want insert a object array. What can I do?
const string dbFileName = "game.db";

const double mageAttackValue = 3.3;
const double mageDefenseValue = 3.4;

const double warriorAttackValue = 4.4;
const double warriorDefenseValue = 2.2;

// create two objects
IHero mage = new Mage("Merlin", mageAttackValue, mageDefenseValue);
IHero warrior = new Warrior("Conan", warriorAttackValue, warriorDefenseValue);

// store them
using (var odb = OdbFactory.Open(dbFileName))
{
    var data = new IHero[] { mage, warrior };

    odb.Store(data);

    //odb.Store(mage);
    //odb.Store(warrior);
}
Apr 29, 2013 at 8:22 AM
Hello,
The simplest solution you can choose is to wrap it with simple class (array holder). The reason why arrays cannot be stored directly is that they are stored in specific in-lined way without all class specific info, which allows you for working with objects.

Regards,
Jacek
Apr 29, 2013 at 5:05 PM
Thanks.