代码:
public static string Serialize<T>(IEnumerable<T> list)
{
BinaryFormatter formatter = new BinaryFormatter();
using (MemoryStream m = new MemoryStream())
{
formatter.Serialize(m, list);
m.Position = 0;
return Convert.ToBase64String(m.ToArray());
}
}
public static T Deserialize<T>(string listData)
{
BinaryFormatter formatter = new BinaryFormatter();
using (MemoryStream m = new MemoryStream())
{
return (IEnumerable<T>)formatter.Deserialize(m); //Problem is here
}
}
错误:
Error 1 Cannot implicitly convert type
'System.Collections.Generic.IEnumerable<T>' to 'T'. An
explicit conversion exists (are you missing a cast?)