ArrayList在vb.net项目中被覆盖 [英] ArrayList is overwritten in vb.net Project

查看:85
本文介绍了ArrayList在vb.net项目中被覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我是VB.net的新手,我在项目中使用了ArrayList,并且观察到arraylist会覆盖arraylist中的先前项目.

Dear All,

I am very new to VB.net, I used ArrayList in a project and I observed that arraylist overwrites the previous items in the arraylist.

<serializable()> _
Public Class benchPortalPara

    Public name As String = ""
    Public attribute As String = ""
    Public time As Double = 0.0
    Public CmdCnt As Integer = 0 ''ToDo: to remove

    <(XmlArrayItem(Type:=GetType(benchPortalPara)), _
    ''XmlArrayItem(Type:=GetType(CLS_BENCH_CMD_ALARM))> _
    ''Public benchList As ArrayList = New ArrayList

    <XmlArrayItem(Type:=GetType(benchPortalPara))> _
    Public benchList As ArrayList

    Public Shared Instance As benchPortalPara = Nothing

    Public Shared Sub passCmdData(ByVal Cls_Cmd As CLS_BENCH_CMD_TIMING)
        If (Instance Is Nothing) Then
            Instance = New benchPortalPara
        End If
        Instance.name = Cls_Cmd.cmdName
        Instance.attribute = Cls_Cmd.cmdDescription
        Instance.time = Cls_Cmd.duration
        Instance.CmdCnt += 1

        If (Instance.benchList Is Nothing) Then Instance.benchList = New ArrayList()
        Instance.benchList.Add(Instance)
    End Sub
End Class


每当我调用passCmdData()例程时,我以前的arraylist数据都会被覆盖.

请提示出什么问题可以解决?

预先感谢,

Naveed


Everytime when I call passCmdData() routine, my previous arraylist data is overwritten.

Please suggest that what can go wrong?

Thanks in advance,

Naveed

推荐答案

为什么您的类似乎拥有自己的实例,称为Instance?
为什么不使用我呢?
Why does your class appear to hold an instance of itself, called Instance?
Why not use Me instead?
If (Me.benchList Is Nothing) Then Me.benchList = New ArrayList()
Me.benchList.Add(Instance)


这篇关于ArrayList在vb.net项目中被覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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