Results 1 to 3 of 3

Thread: question regarding methods that seem to do the same thing

  1. #1
    Member
    Join Date
    2010-08
    Posts
    40
    Login to Give a bone
    0

    Default question regarding methods that seem to do the same thing

    Okay so new-ish to .NET, wrote an app to insert blocks, rotate, set layer, etc. So question, when accessing the database's what is the difference between these three methods? any particular benefits of one form over the other?
    i seem to be using each of these three in various forms throughout the app.
    Code:
     
    Dim bt As BlockTable
                    bt = tr.GetObject(db.BlockTableId, _
                                       OpenMode.ForRead)
    
                    Dim bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead)
    
                    Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)

  2. #2
    I could stop if I wanted to
    Join Date
    2007-08
    Posts
    202
    Login to Give a bone
    0

    Default Re: question regarding methods that seem to do the same thing

    Hi,

    The first two ones (green and blue) are exactly the same except formating (carriage returns allows to read the whole expression without scrolling in case it displays in a narrow window).

    The third (red) uses explicit cast to the BlockTable type.

    The Transaction.GetObject method returns a DBObject instance you need to downcast into a BlockTable instance.
    If Option Strict is off (default), the compiler will (try to) implicitly cast the returned DBObject if you don't explicitly do it as in the third expression. All the upper expressions will work with Option strict Off.
    If Option Strict is on, you must use explicit casts as in the third expression.

    C# and F# are stricter languages and do not allow implicit type conversions.

    About VB options, you can have a look here:
    http://support.microsoft.com/kb/311329

    About

  3. #3
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: question regarding methods that seem to do the same thing

    The other difference between 1 and 2 is that is that 2 combines the declaration and assignment in the same line rather than 2 lines like example 1 does.
    C:> ED WORKING....


    LinkedIn

Similar Threads

  1. I need help in Methods vla
    By ederson_ambrosio in forum AutoLISP
    Replies: 2
    Last Post: 2009-05-11, 12:05 PM

Posting Permissions

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