简体   繁体   中英

Converting a VB.NET Shared Function to C#

I used a converter program to convert this vb to 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. I don't even use ref much if at all and don't think this is the best/cleanest way to convert this. 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). 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. 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.

Looks like a [mostly] correct conversion to me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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