提问人:Nathaniel Turner 提问时间:8/8/2023 最后编辑:Nathaniel Turner 更新时间:8/11/2023 访问量:71
从 2d 数组列表创建新列表 在 VB.NET 中
creating a NEW list from a 2d array list In VB.NET
问:
我一直在尝试我能想到的一切,但我无法让它发挥作用。我正在尝试从 2D 数组创建一个列表。这样做的原因是为了让我可以创建一个 XY 图形,并使用网格线来指示所选项目在我的图形中的位置。我附上了我的想法的手绘,如果这对任何人也有帮助的话。简单来说,每次在我的 2D 数组中都会遇到一个读取 testtesttest 的文件。D000 我需要将其存储到一个单独的列表中,以便我可以将其用于我的 x 轴。我正在使用 List(Of String) 来创建我当前拥有的内容。我尝试过的所有方法似乎都无法在新列表中自行获取这些选择文件。下面的代码当前读取所有文件并将它们放在正确的位置。使用.轴X。让它工作的命令?
'2D ARRAY
reader = New streamReader("R:PathTooriginalFile.csv")
Dim stAll as String = reader.ReadToEnd
reader.Close()
MonitorIDTextFile = New StreamWrite("R:PathToWhereICoppiedTheFile", False)
MonitorIDTextFiles.WriteLine(stALL) MonitorIDTextFile.close()
'X-Axis Define
**strong text**Dim LinesForDateOfTheFile =
File.ReadAllLines("R:PathToWhereICoppiedTheFile") For x_DOF = 1 to
LineCount
Dim data = LinesForDateOfTheFile(x_DOF)
Dim splits = data.Split(","c)
For y_DOF = 0 To myarray.GetUpperBound(1)
myarray(x_DOF, y_DOF) = splits(y_DOF)
DateOfFile = myarray(x_DOF, 3)
Next
DateOfTheFileValues.Add(DateOfFile)
Next
CountsOfTheDateOfFile = DateOfTheFileValues.Count -1
'Y-AXIS Define
Dim LinesForCR1 =
File.ReadAllLines("R:PathToWhereICoppiedTheFile") For x_CR1 = 1 to
LineCount
Dim data = LinesForCR1(x_CR1)
Dim splits = data.Split(","c)
Dim StringConversion As Single
For y_CR1 = 0 To myarray.GetUpperBound(1)
myarray(x_CR1, y_CR1) = splits(y_CR1)
GrossCR1 = myarray(x_CR1, 44)
Next
StringConversion = CSng(GrossCR1)
GrossCR1 = StringConversion
GrossCR1Values.Add(GrossCR1) Next CountsOfCR1 = GRossCR1Values.Count -1
'Plot Graph
ChartName.Titles.Add("Name Of
Chart") ChartName.ChartAreas.Clear()
ChartName.ChartAreas.Add("Default") With
ChartName.ChartAreas("Dedault")
Dim i As Integer
For i = 0 to CountsOfDateOfFile
Next
.AxisX.Title = "Date"
.AxisY.Title = "Counts"
.Axisx.MajorGrid.LineColor = Color.Red
.Axisx.Maximum = CountsOfDateOfFile
.AxisY.MajorGrid.LineColor = Color.Orange
ChartName.ChartAreas(0).AxisY.IsLogarithmic = True
ChartName.Series.Clear() End With
ChartName.Add("CR1")
ChartName.Series("CR1").Color = Color.DarkTurquoise
ChartName.Series("CR1").BorderDashStyle =
DataVisualization.Charting.ChartDashStyle.Dot
ChartName.Series("CR1").BorderWidth = 4
ChartName.Series("CR1").ChartType =
DataVisualization.Charting.SeriesChartType.Point
For i1 As Integer = 0 To CountsOfCR1
Dim y1 As Single
Dim x1 AS Single
x1 = DateOfFileValues(i1)
y1 = GrossCR1Values(i1)
If y1 = 0 Then y1 = 1
ChartName.Series("CR1").Points.AddXY(x1, y1)
Next
答:
0赞
Gary S
8/11/2023
#1
若要使用 vb.net 从 ArrayList 创建新 List,请枚举 ArrayList 中的项并将每个项添加到 List。
Dim anArrayList As New ArrayList()
anArrayList.Add("sampleData3")
anArrayList.Add("sampleData4")
Dim lstString As New List(Of String)
For Each item As String In anArrayList
lstString.Add(item)
Next
For Each item In lstString
Diagnostics.Debug.WriteLine(item)
Next
''expected output:
''sampleData3
''sampleData4
若要从 Array 而不是 ArrayList 开始,请使用:
将 lstString 调暗为 List(Of String) = arrString.ToList()
我正在尝试从 2D 数组创建一个列表。
Dim arrString(2) As String
arrString(1) = "sampleData1"
arrString(2) = "sampleData2"
Dim lstString As List(Of String) = arrString.ToList()
For Each item as String In lstString
Diagnostics.Debug.WriteLine(item)
Next
'expected output:
'sampleData1
'sampleData2
评论
List(Of T)
T
List(Of String)