SkyeBoniwell
SkyeBoniwell

Reputation: 7092

Class properties in VB.NET 4.0

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.)

Upvotes: 2

Views: 170

Answers (2)

Gratzy
Gratzy

Reputation: 9389

r is a DataRow. It has an extension method of .Field:

WorkID = r.Field(Of Int32)("workID")

It means: set WorkID to the value of the column in the data row with the name "workID" and the type of that value is Int32.

Upvotes: 1

Reed Copsey
Reed Copsey

Reputation: 564333

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 DataRow that's already initialized (and has all of the values). The three properties (UserID, WorkID, and OfficialGroupID) of the object will get their values from the "userID", "workID", etc. fields of the row.

Upvotes: 3

Related Questions