Results 1 to 12 of 12

Thread: Dim s As [String] = [String].Emtpy

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382

    Dim s As [String] = [String].Emtpy

    Dim s As [String] = [String].Emtpy

    Is that a valid declaration in vb.net?

    I see it in some example code in the msdn but I have no clue what the brackets are for. Can anyone enlighten me?

    Also when you actually type the the statement, after you type "As [String]", the IDE removes the Brackes, so only way to do add this kind of declaration is to paste the whole thing and then it will stay.. Can anyone clue me in?

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Not sure why you would need any brackets..... if it takes them off, then they are not needed.

    Dunno why the MSDN shows them.... maybe just so you know it's a string?

  3. #3
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    it equates to this :
    VB Code:
    1. [COLOR=BLUE]Dim[/COLOR] s [COLOR=BLUE]As[/COLOR] [COLOR=BLUE]String[/COLOR] = [COLOR=BLUE]String[/COLOR].Empty

    the [ ] get removed automatically if you type it with them in
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  4. #4
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by dynamic_sysop


    the [ ] get removed automatically if you type it with them in


    He wanted to know why the MSDN showed code like that with the brackets, he already posted that VB automaticly takes them off....

  5. #5
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    yeah i overlooked that small detail lol
    anyway , the [ ] are only there as you said , to show it's a string.
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382
    Hmm, I don't think it's just to "express" that it's a string because there are certain areas in the code where they have it.. As I said, you can actually paste the whole thing and it will work and the IDE will retain the brackets and it will act as a string. I'm thinking that this might have been something from beta or a earlier version of .Net that actually used the brackets.. see for yourself.. paste this into your browser and look at the code..

    ms-help://MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpguide/html/cpconnon-blockingserversocketexample.htm

    Interesting...

  7. #7
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    i couldnt find that link to open it , should it have a http:// bit on it somewhere?
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  8. #8
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by dynamic_sysop
    i couldnt find that link to open it , should it have a http:// bit on it somewhere?
    No, it's a stupid propriatary MS crap for IE.... ugh I hate how they make up there own web ****...

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382
    Link Here


    sorry, the first link was a local MSDN link.. works if you have 2003 msdn installed and IE on your machine

  10. #10
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    The brackets are used when a word can have two meanings in the current namespace. For instance if you want to use a shared method of the Enum class you'd have to use [Enum] or else it will think you are trying to declare an Enum. So either the example just used it to show it is using a member of the String class or something about the namespace made it be used.
    VB Code:
    1. <Flags()> _
    2.     Enum QueryTypes
    3.         [Select] = 1
    4.         Insert = 2
    5.         Update = 4
    6.         Delete = 8
    7.     End Enum
    8.  
    9.         Dim x As QueryTypes = [Enum].Parse(GetType(QueryTypes), "Insert")
    10.         MsgBox(x.ToString)

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382
    Thank you Edneeis, that clears things up

  12. #12
    Addicted Member Sheppe's Avatar
    Join Date
    Sep 2002
    Location
    Kelowna, BC
    Posts
    245
    Originally posted by Edneeis
    The brackets are used when a word can have two meanings in the current namespace. For instance if you want to use a shared method of the Enum class you'd have to use [Enum] or else it will think you are trying to declare an Enum. So either the example just used it to show it is using a member of the String class or something about the namespace made it be used.
    VB Code:
    1. <Flags()> _
    2.     Enum QueryTypes
    3.         [Select] = 1
    4.         Insert = 2
    5.         Update = 4
    6.         Delete = 8
    7.     End Enum
    8.  
    9.         Dim x As QueryTypes = [Enum].Parse(GetType(QueryTypes), "Insert")
    10.         MsgBox(x.ToString)
    Sweet! Just like in SQL. That's good to know. Thanks Edneeis!
    [vbcode]
    On Error Goto Hell
    [/vbcode]
    Sheppe Pharis, MCSD
    Check out http://www.vb-faq.com
    Click here for access to the free Code-Express source code and component sharing network for VB6
    Want a better way to skin your .NET applications? Click here!

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