本文介绍了保持数据一段时间(例如4-5天)的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

平台为单点触控我为iPhone开发了一个应用程序.我有一堂课叫Globals.全局"对象在游戏过程中从用户界面和计算中收集条目.

The platform is monotouchI develop an app for iphone.I have a class called Globals. The "Globals" object collects the entries from UI and the calculations during the game.

我计划序列化对象并将其流式传输到txt文件.并在游戏再次启动时将其恢复.(请记住,我只创建由用户终止的程序的序列化文件)

I plan to serialize the object and stream it to a txt file . And recover it when the game launched again. ( Remember I create the serialized file only the program terminated by the user)

从用户终止程序后,我就使用反序列化的对象继续运行.

I use the deserialized object to go on from the moment of the user has terminated the program.

这样可以吗?这是最好的做法吗?或者我需要使用其他方式来始终保留游戏的信息.请为此评论或建议最佳做法.

Is this way okay? Is it a best practise? or I need to use other ways to keep the game's info all the time. Please comment or advice a best practise for this purpose.

推荐答案

如果您使用SQLite路由,请查看SQLite.Net,它将保存您的现有对象并几乎不使用任何代码加载它们.

If you go the SQLite route look at SQLite.Net it will save your exiting objects and load them with hardly any code.

https://github.com/praeclarum/sqlite-net#readme

这是一个示例:

// Add some extra atributes as needed to your existing class.
public class Stock
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    [MaxLength(8)]
    public string Symbol { get; set; }
}

创建一个SQLite数据库连接,并确保存在Stock类的表.

Create a SQLite db connection and make sure the table for the class Stock exists.

var db = new SQLiteConnection("foofoo");
db.CreateTable<Stock>();

将一个Stock实例添加到数据库中...例如,保存它!

Add a Stock instance to the DB... eg.. Save it!

public static void AddStock(SQLiteConnection db, string symbol) {
    var s = db.Insert(new Stock() {
        Symbol = symbol
    });
    Console.WriteLine("{0} == {1}", s.Symbol, s.Id);
}

从数据库取回一个或多个库存....

Get one or more Stock(s) back from DB....

public static IEnumerable<Stock> QueryValuations (SQLiteConnection db, int stock)
{
    return db.Query<Stock> ("select * from Stock where StockId = ?", Id);
}

这篇关于保持数据一段时间(例如4-5天)的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 09:28