物品清单 - c#.net等价物 [英] Item List - c#.net equivalent

查看:82
本文介绍了物品清单 - 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.

推荐答案

如果你想将VB翻译成C#,有几个在线转换器可以做得很好:

http://www.developerfusion.com/tools/convert/vb-to-csharp/ [ ^ ]和http://converter.telerik.com/ [ ^ ]工作正常......
If you want to translate VB to C#, there are several online converters which will do a pretty good job:
http://www.developerfusion.com/tools/convert/vb-to-csharp/[^] and http://converter.telerik.com/[^] both work fine...


尝试使用System.Windows.Forms.ListBox.ObjectCollection类。



请参阅 http ://msdn.microsoft.com/en-us/library/system.windows.f orms.listbox.items(v = vs.110).aspx [ ^ ]了解详情。它当然可以帮到你。



谢谢
Try to use the System.Windows.Forms.ListBox.ObjectCollection class.

Refer to http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.items(v=vs.110).aspx[^] for details. It should certainly help you.

Thanks


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

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