CSVUtil.ReadCSV C# (CSharp) Method

ReadCSV() public static method

public static ReadCSV ( string filePath ) : ].string[
filePath string
return ].string[
	public static string [,] ReadCSV (string filePath) {
		string csvAsString = FileUtil.FileText(filePath);

		string[] byLine = csvAsString.Split('\n');

		int columns = GetMaxRowLength(byLine);
		int rows = byLine.Length;

		string[,] byCell = new string[columns, rows];

		for (int x = 0; x < columns; x++) {
			for (int y = 0; y < rows; y++) {
				byCell[x, y] = byLine[y].Split(',')[x];
			}
		}

		return byCell;
	}

Usage Example

        /// <summary>
        /// CSV 表映射到对象
        /// </summary>
        private Dictionary <int, T> ReadCSVTable <T>(string csvName)
        {
            Dictionary <int, T> csvTable = new Dictionary <int, T>();

            CSVUtil.ReadCSV(csvName, csvTable);
            return(csvTable);
        }
All Usage Examples Of CSVUtil::ReadCSV