首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在vb.net中将不同数据类型的列表转换为字符串

如何在vb.net中将不同数据类型的列表转换为字符串
EN

Stack Overflow用户
提问于 2015-06-18 03:02:32
回答 2查看 40关注 0票数 0

我使用一个具有不同数据类型的类创建了一个列表。填充方式如下:

代码语言:javascript
运行
复制
   [1/16/2015 10:30:14 PM] 241.167.2.72:5

   [1/17/2015 11:30:06 PM] 100.133.2.55:6

   [1/18/2015 12:30:33 PM] 206.140.3.10:7

现在我只想在页面上的文本框中显示它。但你要知道:

代码语言:javascript
运行
复制
   ClientWebApp.DedicatedServerApi.Formatted_DDoS_SampleFlows

   ClientWebApp.DedicatedServerApi.Formatted_DDoS_SampleFlows

   ClientWebApp.DedicatedServerApi.Formatted_DDoS_SampleFlows

我在ToString()...but中使用了这行代码,显然这是不正确的。

strSampleFlowLine = formattedDDoSSampleFlow.ToString() & vbCrLf & vbCrLf

有什么想法吗?

尝试填充页面上的文本框的代码(和类):

代码语言:javascript
运行
复制
    Dim ddosDetailsInfoResult As New DedicatedServerApi.DDoSDetailsInfoResult
    Dim formattedDDoSSampleFlow As New DedicatedServerApi.Formatted_DDoS_SampleFlows
    ' Create a list field - an array of the DDoS sample flows.
    Dim formattedDDoSSampleFlowsList As New List(Of DedicatedServerApi.Formatted_DDoS_SampleFlows)

        If ddosDetailsInfoResult.DDoS_Details.Formattted_DDoS_SampleFlows_List.Count > 0 Then
            ' Note: had to add .ToList() as it was giving a syntax error: cannot be converted to a 1-dimensional array.
            ' Does not make sense as the "Formattted_DDoS_SampleFlows_List" variable is defined exactly like the receiving field.
            formattedDDoSSampleFlowsList = ddosDetailsInfoResult.DDoS_Details.Formattted_DDoS_SampleFlows_List.ToList()

            For Each formattedDDoSSampleFlow In formattedDDoSSampleFlowsList

                ' Example of entry in the list:    [1/16/2015 10:30:14 PM] 241.167.2.72:5

                strSampleFlowLine = formattedDDoSSampleFlow.ToString() & vbCrLf & vbCrLf

                ' Build the sample flow list textbox.
                txtGDHDApiSampleFlowList.Text = txtGDHDApiSampleFlowList.Text & strSampleFlowLine
            Next
        Else
            'An empty list.
            txtGDHDApiSampleFlowList.Text = ""
        End If

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' Holds formatted DDoS sample flows settings.
'   [1/16/2015 10:30:14 PM] 241.167.2.72:5
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Public Class Formatted_DDoS_SampleFlows
    Private _open_bracket_delimeter As String

    Public Property Open_Bracket_Delimeter() As String
        Get
            Return _open_bracket_delimeter
        End Get

        Set(value As String)
            _open_bracket_delimeter = value
        End Set
    End Property

    Private _time_received As Date

    Public Property Time_Received() As Date
        Get
            Return _time_received
        End Get

        Set(value As Date)
            _time_received = value
        End Set
    End Property

    Private _close_backet_and_space_delimeter As String

    Public Property Close_Bracket_And_Space_Delimeter() As String
        Get
            Return _close_backet_and_space_delimeter
        End Get

        Set(value As String)
            _close_backet_and_space_delimeter = value
        End Set
    End Property

    Private _source_ip As String

    Public Property Source_IP() As String
        Get
            Return _source_ip
        End Get

        Set(value As String)
            _source_ip = value
        End Set
    End Property

    Private _colon1_delimeter As String

    Public Property Colon1_Delimeter() As String
        Get
            Return _colon1_delimeter
        End Get

        Set(value As String)
            _colon1_delimeter = value
        End Set
    End Property

    Private _source_port As String

    Public Property Source_Port() As String
        Get
            Return _source_port
        End Get

        Set(value As String)
            _source_port = value
        End Set
    End Property 
End Class

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' Holds DDoSDetailsInfoResult.
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Public Class DDoSDetailsInfoResult
    Private _message As String

    Public Property Message() As String
        Get
            Return _message
        End Get

        Set(value As String)
            _message = value
        End Set
    End Property

    Private _ddos_details As New DDoS_Details

    Public Property DDoS_Details() As DDoS_Details
        Get
            Return _ddos_details
        End Get

        Set(ByVal value As DDoS_Details)
            _ddos_details = value
        End Set
    End Property
End Class    

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' Holds DDoS details.
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Public Class DDoS_Details
    Private _formatted_ddos_sampleflows_list As New List(Of Formatted_DDoS_SampleFlows)

    Public Property Formattted_DDoS_SampleFlows_List() As List(Of Formatted_DDoS_SampleFlows)
        Get
            Return _formatted_ddos_sampleflows_list
        End Get

        Set(ByVal value As List(Of Formatted_DDoS_SampleFlows))
            _formatted_ddos_sampleflows_list = value
        End Set
    End Property
End Class
EN

回答 2

Stack Overflow用户

发布于 2015-06-18 03:05:38

您的Formatted_DDoS_SampleFlows类需要定义ToString的作用。

类似于:

代码语言:javascript
运行
复制
Class Formatted_DDoS_SampleFlows

    Public Overrides ToString() As String

        Return _open_bracket_delimeter & _time_received.ToString() & _close_backet_and_space_delimeter & _source_ip
    End Sub

End Class
票数 2
EN

Stack Overflow用户

发布于 2015-06-18 03:07:21

使用CDate将原始值转换为日期。ToString正在整个类上运行。然后使用String.Format将日期输出为所需的正确格式。应该看一些更接近这个的东西:

代码语言:javascript
运行
复制
strSampleFlowLine = String.Format("MM/dd/yyyy", CDate(formattedDDoSSampleFlow.something)) & vbCrLf & vbCrLf
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30900207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档