简体   繁体   English

将C#转换为VB.NET:为什么看不到静态方法?

[英]Converting C# to VB.NET: why is static method not visible?

I have a C# method in my datatier that I am trying to convert to VB.Net. 我的数据层中有一个C#方法,我试图将其转换为VB.Net。 I converted it to VB.Net but when I bring up the datatier class the method is not showing. 我将其转换为VB.Net,但是当我打开数据层类时,该方法未显示。 It has been a long time since i have used VB.Net and forgot alot of things 自从我使用VB.Net并忘记了很多东西以来已经有很长时间了

Here is my c# method: 这是我的C#方法:

public static useraccount UserActInfo(string empnumber)
{
    SQLConnectivity db = new SQLConnectivity();
    SqlParameter[] param = new SqlParameter[1];
    DataTable dt = new DataTable();
    useraccount user = new useraccount();

    param[0] = db.MakeInputParameter("@UserEmpNumber", empnumber);
    db.RunExecuteProcedure("dc_SELECT_UserActInfo_By_EmpNumber", param, ref dt);

    if (dt != null && dt.Rows.Count > 0)
    {
        user.ID = Convert.ToInt32(dt.Rows[0]["UserID"].ToString());
        user.FirstName = dt.Rows[0]["FName"].ToString();
        user.LastName = dt.Rows[0]["LName"].ToString();
        user.MiddleName = dt.Rows[0]["MName"].ToString();
        user.Title = dt.Rows[0]["Title"].ToString();
        user.PhoneNo1 = dt.Rows[0]["PhoneNumber1"].ToString();
        user.PhoneNo2 = dt.Rows[0]["PhoneNumber2"].ToString();
        user.Fax = dt.Rows[0]["FaxNumber"].ToString();
        user.Email = dt.Rows[0]["Email"].ToString();
        user.StreetAddress = dt.Rows[0]["StreetAddress"].ToString();
        user.Locality = dt.Rows[0]["Locality"].ToString();
        user.Province = Convert.ToInt32(dt.Rows[0]["Province"].ToString());
        user.PostalCode = dt.Rows[0]["PostalCode"].ToString();
        user.EmpNumberID = Convert.ToInt32(dt.Rows[0]["EmployeeNumberID"].ToString());
        user.EmpNumber = dt.Rows[0]["EmployeeNumber"].ToString();
    }
    if (user.ID != 0) { return user; }
    else { return null; }
}

I believe it has to do with the declaration, which i have as: 我认为这与声明有关,我的声明如下:

Public Static Function UserActInfo(ByVal _eno As String) As useraccount

Why can I not see the method 为什么看不到方法

Static in C# is Shared in VB.Net. C#中的静态在VB.Net中共享。

So if you convert your code above it will be: 因此,如果在上面转换代码,它将是:

 Public Shared Function UserActInfo(ByVal empNumber As String) As UserAccount
     'code here
 End Function

You could use this online converter by Telerik to help you with the conversions. 您可以使用Telerik的此在线转换器来帮助您进行转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM