【发布时间】:2011-02-06 09:19:34
【问题描述】:
使用未分配的局部变量“模型”。是我收到的错误消息。它就在我说 if (model == null) 的地方。我不知道为什么它给我一个编译时错误..有人请帮忙。
public static T TryGet<T>(string fileName) where T : new()
{
T model;
using (var storageFile = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var stream = new IsolatedStorageFileStream(fileName, FileMode.Open, storageFile))
{
if (stream.Length > 0)
{
var serializer = new DataContractSerializer(typeof(T));
model = (T)serializer.ReadObject(stream);
}
}
}
if (model == null)
{
model = new T();
}
return model;
}
【问题讨论】: