繁体   English   中英

将 VB.NET 共享 Function 转换为 C#

[英]Converting a VB.NET Shared Function to C#

我使用转换器程序将此 vb 转换为 C#

Public Overloads Shared Function ExecuteReader(ByVal statement As String, ByVal commandType As CommandType, _
    ByVal paramCollection As ArrayList, ByVal connectionDelegate As OpenDatabaseConnection, _
    ByVal outputConnectionObject As IDbConnection, ByVal CommandTimeout As Int16) As InstantASP.Common.Data.IDataReader

Return PrivateExecuteReader(Configuration.AppSettings.DataProvider, _
    statement, commandType, paramCollection, connectionDelegate, outputConnectionObject, CommandTimeout)

End Function

我对 VB.NET 不熟悉,我不知道为什么这个转换器使用所有这些参考将它转换为 C#。 我什至根本不使用 ref 并且不认为这是转换它的最佳/最干净的方法。 但是我无法理解所有这一切,包括转换,以及转换后这是否有意义。

public static IDataReader ExecuteReader(string statement, CommandType commandType, ArrayList paramCollection, OpenDatabaseConnection connectionDelegate, IDbConnection outputConnectionObject, Int16 commandTimeout)
{
    return PrivateExecuteReader(ref AppSettings.DataProvider(), ref statement,
        ref commandType, ref paramCollection, ref connectionDelegate,
        ref outputConnectionObject, ref commandTimeout);
}

它将ref放在这些参数上,因为PrivateExecuteReader()将它们声明为ref (C#) 或ByRef (VB.NET)。 没有选择。

在 VB.NET 中,您只需传入您的 arguments 并且必须查看方法的声明(或 Intellisense 提示)以了解它是通过引用还是通过值。 但是在 C# 中,如果方法将参数声明为ref ,那么您还必须将要传递的参数标记为ref ,以便明确了解它是通过引用传递的。

对我来说,这似乎是一个 [大部分] 正确的转换。

暂无
暂无

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

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