Results 1 to 10 of 10

Thread: [2005] Question about writing a class

  1. #1

    Thread Starter
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    [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!

    In the unlikely event that I answer your question correctly, please Rate my post

    Using Visual Studio 2005 Professional

  2. #2
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    261

    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

  3. #3

    Thread Starter
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    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!

    In the unlikely event that I answer your question correctly, please Rate my post

    Using Visual Studio 2005 Professional

  4. #4
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: [2005] Question about writing a class

    The _ usually indicates member vairables lots of microsoft people use the mixture of _ and m_variable.

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  6. #6

    Thread Starter
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    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)

    In the unlikely event that I answer your question correctly, please Rate my post

    Using Visual Studio 2005 Professional

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  8. #8

    Thread Starter
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    Re: [2005] Question about writing a class

    ohhh i see... kinda

    So your tagging the DataObject attribute to the class... i got that

    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:
    1. <System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, True)> _
    2.     Public Function GetProducts() As Northwind.ProductsDataTable
    3.         Return Adapter.GetProducts()
    4.     End Function

    In the unlikely event that I answer your question correctly, please Rate my post

    Using Visual Studio 2005 Professional

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  10. #10

    Thread Starter
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    Re: [2005] Question about writing a class

    Excellent! That clears things up a bit!

    In the unlikely event that I answer your question correctly, please Rate my post

    Using Visual Studio 2005 Professional

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width