I’ve been assigned to document some new code, and I can’t figure out how the code below works. This is the new Sub for a public class.
I am guessing that “r” stands for row, but how are the three properties getting the data? I can’t find anything in the code that would help shed light on this.
Protected Sub New(ByVal r As DataRow)
UserID = r.Field(Of Int32)("userID")
OfficialGroupID = r.Field(Of Guid?)("officialGroupID")
WorkID = r.Field(Of Int32)("workID")
End Sub
What is happening here?
(I’m new to .NET, coming from ASP Classic.)
This is a constructor – it’s getting a DataRow passed to it (“r”), and using the values of the fields within that row to initialize its properties.
Basically, when this type is created, you have to pass it a
DataRowthat’s already initialized (and has all of the values). The three properties (UserID,WorkID, andOfficialGroupID) of the object will get their values from the “userID”, “workID”, etc. fields of the row.