Reputation: 1290
I have a List defined as the following:
List<Tuple<string, long, DateTime>> firefoxBookmarkPaths = new List<Tuple<string, long, DateTime>>();
However I'm having trouble adding to my list:
List<Tuple<string, long, DateTime>> firefoxBookmarkPaths = new List<Tuple<string, long, DateTime>>();
long fileSize = 0;
string bookmarkFile = null;
string directoryToCheck = null;
DateTime fileModifiedDate = DateTime.MinValue;
foreach (var dir in basePersistDirectories)
{
directoryToCheck = dir + @"\C\Users" + @"\" + Environment.UserName + @"\" + @"AppData\Roaming\Mozilla\Firefox\Profiles";
if (Directory.Exists(directoryToCheck))
{
var subDirectories = Directory.GetDirectories(directoryToCheck);
foreach (var directory in subDirectories)
{
bookmarkFile = directory + @"\places.sqlite";
if (File.Exists(bookmarkFile))
{
fileSize = new FileInfo(bookmarkFile).Length;
fileModifiedDate = new FileInfo(bookmarkFile).LastWriteTimeUtc;
}
}
firefoxBookmarkPaths.Add(bookmarkFile, fileSize, fileModifiedDate);
}
}
The line firefoxBookmarkPaths.Add(bookmarkFile, fileSize, fileModifiedDate);
is throwing error "No overload for method 'Add' takes 3 arguments." How can I add elements to this list?
Upvotes: 0
Views: 66
Reputation: 783
You are not calling .Add() with a tuple, you are calling .Add() with three parameters, which it has no overloaded method for (as the error message tells you). Instead, you'll need to do something like this:
firefoxBookmarkPaths.Add(Tuple.Create(bookmarkFile, fileSize, fileModifiedDate));
Or, if you are using C# 7.0, you can use some syntactic sugar:
firefoxBookmarkPaths.Add((bookmarkFile, fileSize, fileModifiedDate));
Edit
As pointed out in a comment below, this is not syntactic sugar, but a different type. Although if you are using C# 7.0, using the different type would also be good.
Upvotes: 5
Reputation: 216293
List<T>Add
method requires a T value when you try to add something.
So your line should be
firefoxBookmarkPaths.Add(new Tuple<string, long, DateTime>
(bookmarkFile, fileSize, fileModifiedDate));
Upvotes: 2