“对象的1维数组”类型的值无法转换为“System.Collections.ArrayList”。 [英] Value of type '1-dimensional array of Object' cannot be converted to 'System.Collections.ArrayList'.

查看:200
本文介绍了“对象的1维数组”类型的值无法转换为“System.Collections.ArrayList”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试从wcf服务从db获取数据并发送到我的vb表单但是当我收到错误时我卡住了类型的值'1维数组对象'无法转换为'System.Collections.ArrayList'。这是我的代码,请让我知道改进的代码。



VB代码:

Hi,

I am trying to fetch data from db from wcf service and send to my vb form but I am stuck when i got error " Value of type '1-dimensional array of Object' cannot be converted to 'System.Collections.ArrayList'." Here is my code please let me know improved code for this.

VB Code:

Private Sub btn_login_submit_Click(sender As Object, e As EventArgs) Handles btn_login_submit.Click
        Dim loginService As LoginServiceReference.ILoginService
        Dim dt As New ArrayList
        dt = loginService.validateUser(txt_uname.Text, txt_psw.Text)

    End Sub
End Class







ILoginService .vb




ILoginService.vb

<ServiceContract()>
Public Interface ILoginService

    <OperationContract()>
    Function validateUser(uname As String, psw As String) As ArrayList

End Interface









ILoginService.svc .vb







ILoginService.svc.vb

Function validateUser(ByVal uname As String, ByVal psw As String) As ArrayList Implements ILoginService.validateUser
       Dim userStatus As Boolean = False
       Dim dc As New UserLoginDataContext()
       Dim udata As ArrayList = From t In dc.User_LoginInfos Where t.UserName = uname & t.U_password = psw Select t

       If (udata.Count > 0) Then
           userStatus = True
       Else
           userStatus = False
       End If

       udata.Add(userStatus)
       Return udata
   End Function

推荐答案

这是一个问题。



为什么你甚至使用ArrayList?自从.NET 2.0问世以来,它几乎已成为一个死的集合。早在2005年,我就不知道有谁使用它了。



接下来,a无论如何,一个名为 validateUser 的方法并不建议它应该返回除布尔值以外的任何东西。



BTW,方法名称不应以小写字母开头,以区别于驼峰变量名。
Here's a question.

Why are you even using ArrayList? It's pretty much been a dead collection since .NET 2.0 came out, back in 2005. I don't know anyone who uses it, for anything.

Next, a method called validateUser does not suggest, to me anyway, that it should be returning anything other than a Boolean value.

BTW, method names should not start with a lower case letter to differentiate them from camel-cased variable names.


这篇关于“对象的1维数组”类型的值无法转换为“System.Collections.ArrayList”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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