Class Question


S

shapper

Hello,

I am creating a class "User" which will be used in Asp.Net 2.0 profile.
The class "User" has 2 properties: "Name" of type string and "Books"
which should be a collection of various "Book".
Then I want to be able to Add or Remove a "Book" from "Books"
collection under class "User".

Could someone tell me how to do this?

Here is the code I created. This is far from being working:

<Serializable()> _
Public Class User

' Name
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property

' Books
Private _Books As Book
Public Property Books() As Book
Get
Return _Books
End Get
Set(ByVal value As Book)
_Books = value
End Set
End Property

End Class

...........................

<Serializable()> _
Public Class Book

' Title
Private _Title As String
Public Property Title() As String
Get
Return _Title
End Get
Set(ByVal value As String)
_Title = value
End Set
End Property

' Editor
Private _Editor As String
Public Property Editor() As String
Get
Return _Editor
End Get
Set(ByVal value As String)
_Editor = value
End Set
End Property

End Class

Thanks,
Miguel
 
Ad

Advertisements

E

Eric

Instead of declaring _Books as type Book, you need a collection. There
are many in the System.Collections namespace. Collections generally
have a method like Add() for adding elements and [] operators for
retrieving them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top