天天看點

VB.NET 中的ref 和C#中的ref 格式差別

今天把一個VB.NET的程式翻成C#的,在ref這堵了半天。

函數定義是這樣的:

Public Shared Function GetUsers(ByVal portalId As Integer, ByVal isHydrated As Boolean, ByVal pageIndex As Integer, ByVal pageSize As Integer, ByRef totalRecords As Integer) As ArrayList

在VB.NET中可以這樣引用:

Users = UserController.GetUsers(UsersPortalId, False, CurrentPage - 1, PageSize, TotalRecords)

但在C#中,引用要加上"ref",參見MSDN:

ref(C# 參考)

Users = UserController.GetUsers(UsersPortalId, false, CurrentPage-1, PageSize, ref TotalRecords);