Results 1 to 5 of 5

Thread: optional parameters cannot have structure types?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    optional parameters cannot have structure types?

    ok i would just like to know why. optional parameters cannot have structure types?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: optional parameters cannot have structure types?

    Optional parameters actually can have structure types, but only if that structure has a corresponding native data type, e.g. Int32 and Integer. The reason is that the default value for optional parameters must be either a constant or Nothing, but Nothing is only really nothing for reference types. For value types, Nothing is an instance with default values, which doesn't qualify as constant.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: optional parameters cannot have structure types?

    http://www.vbforums.com/showthread.php?t=420153
    Quote Originally Posted by jmcilhinney
    When you declare an optional parameter you have to specify a constant as the default value. You cannot do that with a structure unless it is one of the in-built types. Colours are properties of the Color type, i.e. NOT constants. You can declare an optional parameter that is a class type but for the same reason the only default value you can give it is Nothing. The one exception to this is String because it is also an in-built type, even though it's a class.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: optional parameters cannot have structure types?

    Well, at least I'm consistent! Basically the same answer, three and a half years apart. pacerier, hopefully this shows you why you should ALWAYS search before asking a question. There's a very high probability that you're not the first to ask it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Re: optional parameters cannot have structure types?

    ok sry 'bout dat, i will try to do more searching in the future before posting

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