2011-08-05 44 views

回答

7

如果您要做的只是存儲檢索值,那麼我會推薦使用IsolatedStorage,特別是ApplicationSettings類。

它的一個例子是使用:

using System.IO.IsolatedStorage; 

//storing value 
int someValue = 10; 
IsolatedStorageSettings.ApplicationSettings.Add("MyKey",someValue); 

//write or update value 
IsolatedStorageSettings.ApplicationSettings["MyKey"] = someValue; 

//write to disk 
IsolatedStorageSettings.ApplicationSettings.Save(); 


//reading value 
if(IsolatedStorageSettings.ApplicationSettings.Contains("MyKey")) 
{ 
    int readValue = (int) IsolatedStorageSettings.ApplicationSettings["MyKey"]; 
} 

芒果現在提供MSSqlCE支持,但對於一組值,這是矯枉過正。如果您需要存儲關係數據,而不是持久化用戶/應用程序設置,則數據庫更合適。

雖然IsolatedStorage很好,但讀取和寫入操作可能很昂貴。避免從UI線程讀取IsolatedStorage,這會導致您的應用看起來沒有反應。

+0

我會檢查出來,並回復給你,謝謝你的幫助 –

+0

我不斷收到這個錯誤:「價值不符合預期範圍」,我沒有檢查,我沒有重複的價值。無論我使用什麼鍵值... –

+0

@ng_ducnghia聽起來像一個新問題。而且woudl幾乎肯定需要你顯示你的代碼以便eb回答。 –

相關問題