本文介绍了物品清单 - c#.net等价物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从vb.net迁移到c#.net。在我在vb.net的项目中,我编写以下代码来存储和检索组合框/列表框中的值,它们工作正常。

Hi, I am migrating from vb.net to c#.net. In my projects in vb.net I code the following to store and retrieve values from combobox / listbox and they are working fine.

Public Class CItemList
    Private sName As String
    Private iID As Long

    ' Default empty constructor.
    Public Sub New()
        sName = ""
        iID = 0
    End Sub

    Public Sub New(ByVal Name As String, ByVal ID As Integer)
        sName = Name
        iID = ID
    End Sub

    Public Property Name() As String
        Get
            Return sName
        End Get
        Set(ByVal sValue As String)
            sName = sValue
        End Set
    End Property

    ' This is the property that holds the extra data.
    Public Property ItemData() As Long
        Get
            Return iID
        End Get
        Set(ByVal iValue As Long)
            iID = iValue
        End Set
    End Property

    ' This is neccessary because the ListBox and ComboBox rely on this method when determining the text to display.
    Public Overrides Function ToString() As String
        Return sName
    End Function
End Class

' adding name and id to listbox
lst.Items.Add(New CItemList("xyz", 1))

'to retrieve value from the combobox / listbox
Dim ItemList As CItemList
ItemList = lst.Items(lst.SelectedIndex)
Return Convert.ToString(ItemList.ItemData)



任何人都可以在c#.net中给我相当于此的内容吗?



通过使用CItemList,我可以轻松存储和检索值。



提前谢谢。


Can anyone please give me the equivalent of this in c#.net ?

By using CItemList I can store and retrieve values easily.

Thank you in advance.

推荐答案



这篇关于物品清单 - c#.net等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 00:14
查看更多