[2005] Question about writing a class
I'm working on a class using a tutorial and I'm wondering about something I'm seeing.
<vbcode>
<System.ComponentModel.DataObject()> _
Public Class ProductsBLL
Private _productsAdapter As ProductsTableAdapter = Nothing
Protected ReadOnly Property Adapter() As ProductsTableAdapter
Get
If _productsAdapter Is Nothing Then
_productsAdapter = New ProductsTableAdapter()
End If
Return _productsAdapter
End Get
End Property
End Class</vbcode>
Why all the underscores (_) ??
In the _productsAdapter declaration, why the underscore?
I'm confused.
Thanks!
Re: [2005] Question about writing a class
Its just a good way to declare variables, easy to see and used as a standard in many shops
Re: [2005] Question about writing a class
wow i've never seen it. So do I call my variables like that too?
thanks for the quick response!
Re: [2005] Question about writing a class
The _ usually indicates member vairables lots of microsoft people use the mixture of _ and m_variable.
Re: [2005] Question about writing a class
The first underscore is a line continuation.
Code:
<System.ComponentModel.DataObject()> _
Public Class ProductsBLL
means:
Code:
<System.ComponentModel.DataObject()> Public Class ProductsBLL
Using underscores in variable names is an old way of indicating private variables in a class.
Re: [2005] Question about writing a class
Quote:
Originally Posted by mendhak
The first underscore is a line continuation.
Code:
<System.ComponentModel.DataObject()> _
Public Class ProductsBLL
means:
Code:
<System.ComponentModel.DataObject()> Public Class ProductsBLL
Using underscores in variable names is an old way of indicating
private variables in a class.
Why have the namespace before the declaration of the class? I've never seen that before (before and after the line continuity)
Re: [2005] Question about writing a class
You're talking about the part in <> right? That's not a namespace, that's an attribute. It is a way of tagging up the function or class. This specific one tags the class as a 'dataobject'.
This means that an object of this class type can be bound to.
Re: [2005] Question about writing a class
ohhh i see... kinda :)
So your tagging the DataObject attribute to the class... i got that :thumb:
But I'm not quite sure what you mean when you say "This means that an object of this class type can be bound to."
Here's a better example perhaps:
VB Code:
<System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, True)> _
Public Function GetProducts() As Northwind.ProductsDataTable
Return Adapter.GetProducts()
End Function
Re: [2005] Question about writing a class
For a DataObject class, the DataObjectMethodAttribute attribute would specify what it does, and whether it's the default method for that dataobject class.
About what I meant. You know about the dataset class. The dataset class can be bound to. The datagrid, when it binds to a dataset, will expect that the dataset knows what information it has, how to retrieve, update, manipulate it.
Similarly, there's your DataObject attributed-class. You're essentially creating a custom dataset specific to your application.
Re: [2005] Question about writing a class
Excellent! That clears things up a bit! :thumb: