我在行收到以下错误_dict.Add(id, ar)
:
你调用的对象是空的
这是我的代码:
public Dictionary<int, byte[]> _dict;
public IDictionary<int, byte[]> dict()
{
string sp = HttpContext.Current.Server.MapPath("Images");
DirectoryInfo folder = new DirectoryInfo(sp);
FileInfo[] files = folder.GetFiles("*.jpg");
foreach (var file in files)
{
string name = file.Name;
int id = Convert.ToInt32(name.Substring(0, name.Length - 4));
FileStream fS = new FileStream(sp + "\\" + name, FileMode.Open, FileAccess.Read);
byte[] ar = new byte[fS.Length];
fS.Read(ar, 0, (int)fS.Length);
fS.Close();
_dict.Add(id, ar);
}
return _dict;
}