_Samples/Example_Csv.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;
using System.Data.Common;
using System.Security.Cryptography;
using System.Reflection;
using System.Collections.Specialized;

//<doc:using>
using ComLib;
using ComLib.CsvParse;
//</doc:using>
using ComLib.Application;


namespace ComLib.Samples
{
    /// <summary>
    /// Example for the CsvParse namespace.
    /// </summary>
    public class Example_Csv : App
    {

        /// <summary>
        /// Run the application.
        /// </summary>
        public override BoolMessageItem Execute()
        {
			//<doc:example>
            // See CommonLibrary.UnitTests Source code for actual csv files.
            string text = GetSampleCsv();
            CsvDoc csv = Csv.LoadText(text, true);

            // 1. Get cell at row 0, column 1
            string cell0 = csv.Get<string>(0, 1);

            // 2. Get cell at row 0, column called "FilePath"
            string cell2 = csv.Get<string>(0, "FilePath");

            // 3. Number of columns
            var colCount = csv.Columns.Count;

            // 4. Number of rows
            var rowCount = csv.Data.Count;

            // 5. Column name at index 2
            var col2 = csv.Columns[1];

            // 6. Get int id at row 2
            var id = csv.Get<int>(2, 0);

            // 7. Iterate over all the cells in column named "Date" starting at row 0.
            csv.ForEach<DateTime>("Date", 0, (row, col, val) => 
            {
                Console.WriteLine(string.Format("Row[{0}]Col[{1}] : {2}", row, col, val.ToString())); 
            });

后面还有 43 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。