我有一个方法,它返回一个
List<DateTime>
,但是我在方法内部运行的代码给了我一个 List<string>
。
如何将List<string>
转换为List<DateTime>
用于我的return
行?
实际上,这是一个接受照片列表并返回它们拍摄日期属性的列表的方法。 //retrieves the datetime WITHOUT loading the whole image
public List<DateTime> GetDateTakenFromImage(List<string> path)
{
List<string> dateTaken = new List<string>();
int cnt = 0;
while (cnt < path.Count())
{
using (FileStream fs = new FileStream(path[cnt], FileMode.Open, FileAccess.Read))
using (Image myImage = Image.FromStream(fs, false, false))
{
PropertyItem propItem = myImage.GetPropertyItem(36867);
dateTaken[cnt] = r.Replace(Encoding.UTF8.GetString(propItem.Value), "-", 2);
}
cnt++;
}
return dateTaken;
我从网站上得到了这段代码,所以我不太确定能否使其返回一个List<DateTime>
。
不过我认为我可以让提供的答案适用于这段代码。
谢谢!
DateTime
。请展示代码。 - p.s.w.gdateTaken[cnt] = ...
,但您不能这样做,请参见我的问题。 - Selman GençdateTaken.Add(...)
。 - Selman Genç