Results 1 to 5 of 5

Thread: Using Extensions thought

  1. #1

    Thread Starter
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Post Using Extensions thought

    I was just reading a developer question who asked something like

    Why is this an error "ListBox1.ItemsCount"

    The obvious response is a typo, missing period, forgot the period between Items and Count. But then what if it was not a mistake? Suppose they have an extension method?

    Code:
       <Runtime.CompilerServices.Extension()> _
       Public Function ListCount(ByVal sender As ListBox) As Int32
          Return sender.Items.Count
       End Function
    Reminds me back in the day when developers didn't include the proper import statements.

    Any ways something to think about when recieving code from an outside source. Of course when sending code do not forget to send the extensions, it can be easy to forget if say they are linked to the code and not physically in the project folder or sub-folders.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Using Extensions thought

    I'm not sure why you put this in CC, as it is waaaay to serious for this forum. I read the same thread. However, your example is an extension ListCount, while you mention the user typing ItemsCount. I believe that you are correct with ListCount rather than ItemsCount from the original thread. While the OP could have been missing a period if they had typed ItemsCount, the same is not true with ListCount. I believe that ListCount was the correct property for VB6 and earlier, which is why somebody suggested that it looked like VB6 code.

    Having said that, the point you were making is entirely valid, and probably should have been made somewhere more substantial than here.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Using Extensions thought

    Quote Originally Posted by Shaggy Hiker View Post
    I'm not sure why you put this in CC, as it is waaaay to serious for this forum. I read the same thread. However, your example is an extension ListCount, while you mention the user typing ItemsCount. I believe that you are correct with ListCount rather than ItemsCount from the original thread. While the OP could have been missing a period if they had typed ItemsCount, the same is not true with ListCount. I believe that ListCount was the correct property for VB6 and earlier, which is why somebody suggested that it looked like VB6 code.

    Having said that, the point you were making is entirely valid, and probably should have been made somewhere more substantial than here.
    Yep, sounds like I used the wrong forum, my apologies

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Using Extensions thought

    Don't apologize. In chit chat, that's a waste of time. Just DUCK!!
    My usual boring signature: Nothing

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Using Extensions thought

    Thread moved.


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