本文整理汇总了C#中CsvReader.Count方法的典型用法代码示例。如果您正苦于以下问题:C# CsvReader.Count方法的具体用法?C# CsvReader.Count怎么用?C# CsvReader.Count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsvReader
的用法示例。
在下文中一共展示了CsvReader.Count方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public void Execute(DocumentStore store)
{
Stopwatch sw = Stopwatch.StartNew();
decimal pos = 0;
var csvReader =
new CsvReader(new StreamReader(File.OpenRead("C:\\coding\\SchoolMap.Net\\Collateral\\extract.csv")),
true);
decimal total = csvReader.Count();
csvReader =
new CsvReader(new StreamReader(File.OpenRead("C:\\coding\\SchoolMap.Net\\Collateral\\extract.csv")),
true);
var batch = new List<School>();
foreach (var line in csvReader)
{
using (IDocumentSession session = store.OpenSession())
{
string id = line[31];
School school = session.Query<School>().SingleOrDefault(x => x.Id == id);
if (school == null)
{
school = new School();
SetSchoolProperties(line, school);
school.Id = id;
}
else
{
SetSchoolProperties(line, school);
}
if (batch.Count == 30)
{
var savingSession = store.OpenSession();
batch.ForEach(savingSession.Store);
savingSession.SaveChanges();
batch.Clear();
}
batch.Add(school);
}
Console.Write("\r{0}% ", Math.Round((++pos/total)*100, 2));
}
sw.Stop();
Console.WriteLine("Completed in {0} minutes");
}
示例2: lastId
public string lastId()
{
using (CsvReader csv = new CsvReader(new StreamReader(pathcsv), true, ';'))
{
int n = csv.Count();
if (n == 0)
return "0";
else
return csv[n - 1, 0];
}
}