我正在使用几个自定义类,需要在一个函数中写入数据并在另一个函数中读取数据。为此,我使用了 XM 文件。
我的问题是当我写数据时。
这是我的代码: Imports System.IO Imports System
Public Class MainForm
Public Class MyClass
Private _id As Integer
Private _somestring As String
Public Property Id() As Integer
Get
Return _id
End Get
Set(ByVal Value As Integer)
_id = Value
End Set
End Property
Public Property Somestring() As String
Get
Return _somestring
End Get
Set(ByVal Value As String)
_somestring = Value
End Set
End Property
End Class
Private Sub mysub()
Dim ListVar As New List(Of MyClass)
' code...code.....code....
Dim newvar As New MyClass()
console.writeline("==== within the loop ====")
For i As Integer = 0 To 2
newvar.Id = I
newvar.Somestring = "hello - " & cstr(I)
ListVar.add(newvar)
console.writeline("listvar(" & i & ")=" & listvar(i).Id)
Next
console.writeline("==== outside the loop ====")
console.writeline("listvar(0)=" & listvar(0).Id)
console.writeline("listvar(1)=" & listvar(1).Id)
console.writeline("listvar(2)=" & listvar(2).Id)
End Sub
End Class
输出:
==== 循环内 ====
列表变量(0)=0
列表变量(1)=1
列表变量(2)=2
==== 循环外 ====
列表变量(0)=2
列表变量(1)=2
列表变量(2)=2
我一定是在做一些愚蠢的事情,但我只是弄清楚它是什么......