简体   繁体   English

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

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

I used a converter program to convert this vb 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

I'm not familiar with VB.NET and I don't know why this converter converted it to C# with all these refs.我对 VB.NET 不熟悉,我不知道为什么这个转换器使用所有这些参考将它转换为 C#。 I don't even use ref much if at all and don't think this is the best/cleanest way to convert this.我什至根本不使用 ref 并且不认为这是转换它的最佳/最干净的方法。 But I'm having trouble understanding all this including the conversion and if this makes any sense whatsoever after the conversion.但是我无法理解所有这一切,包括转换,以及转换后这是否有意义。

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);
}

It put the ref on those parameters because PrivateExecuteReader() declares them as ref (C#) or ByRef (VB.NET).它将ref放在这些参数上,因为PrivateExecuteReader()将它们声明为ref (C#) 或ByRef (VB.NET)。 There isn't a choice.没有选择。

In VB.NET, you just pass in your arguments and have to look at the method's declaration (or Intellisense hints) to know whether it's by reference or by value.在 VB.NET 中,您只需传入您的 arguments 并且必须查看方法的声明(或 Intellisense 提示)以了解它是通过引用还是通过值。 But in C#, if a method declares a parameter as ref , then you also have to mark the argument you're passing as ref so that it is explicit that you understand that it is being passed by reference.但是在 C# 中,如果方法将参数声明为ref ,那么您还必须将要传递的参数标记为ref ,以便明确了解它是通过引用传递的。

Looks like a [mostly] correct conversion to me.对我来说,这似乎是一个 [大部分] 正确的转换。

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

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