如何将此代码转换为二维数组 [英] How do I transform this code into a 2d array

查看:79
本文介绍了如何将此代码转换为二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我当前的代码我applayed静态2d数组,并想从csv文件加载我的数据。 csv文件包含2000行和60列,所以我需要使用for循环但我无法获取csv数据来显示它并将其放入列中。现在所有的双数字都在彼此之下,但它们需要60行双数。任何人都可以帮助我让这个循环工作并将csv数据放在2D数组中。



我尝试过:



使用System;

使用System.Collections.Generic;

使用System.Collections.ObjectModel;

使用System.ComponentModel;

使用System.IO;

使用System.Windows;

使用System.Windows.Controls;



名称空间Test_INotifyPropertyChanged

{

///< summary>

///InteraktionslogikfürMainWindow.xaml

///

公共部分类MainWindow:Window

{

public ObservableCollection< string>东西{得到;组; }

public MainWindow()

{

InitializeComponent();

DataContext = this;

thing = new Thing();

int [,] prijsinflatie = new double [2000,60];

}

公共事物{得到;组; }

}



公共类Thing

{

public ObservableCollection< string> ;东西{得到;组; }



public Thing()

{

stuff = new ObservableCollection< string>();



使用(var reader = new StreamReader(@D:\ActuComp\URM\Q2_Prijsinflatie.csv))

{

List< string> listA = new List< string>();

while(!reader.EndOfStream)

{

var line = reader.ReadLine() ;

var values = line.Split(';');



for(int i = 0; i< 60; i ++ )

{

stuff.Add(values [i]);

}

}

}

}

}

}

this is my current code i applayed static 2d array and wanna load my data inside it from a csv file. The csv file contains 2000 rows and 60 columns so i need to do it with a for loop but i cant get the csv data to display it and get it inside the columns to. Now all the double numbers come underneath eachother but they need in rows of 60 double numbers. Can anyone help me get this loop to work and put the csv data inside a 2D array.

What I have tried:

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Windows;
using System.Windows.Controls;

namespace Test_INotifyPropertyChanged
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
///
public partial class MainWindow : Window
{
public ObservableCollection<string> stuff { get; set; }
public MainWindow()
{
InitializeComponent();
DataContext = this;
thing = new Thing();
int[,] prijsinflatie = new double[2000, 60];
}
public Thing thing { get; set; }
}

public class Thing
{
public ObservableCollection<string> stuff { get; set; }

public Thing()
{
stuff = new ObservableCollection<string>();

using (var reader = new StreamReader(@"D:\ActuComp\URM\Q2_Prijsinflatie.csv"))
{
List<string> listA = new List<string>();
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(';');

for (int i = 0; i < 60; i++)
{
stuff.Add(values[i]);
}
}
}
}
}
}

推荐答案

取而代之手动处理CSV,请尝试使用:快速CSV阅读器 [ ^ ]并将结果绑定到网格 - 基于控制。
Instead of processing the CSV manually, try using this: A Fast CSV Reader[^] and bind the result to a grid-based control.


这篇关于如何将此代码转换为二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆