开发者

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, Int开发者_运维技巧16 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜