Results 1 to 4 of 4

Thread: [RESOLVED] [2.0] Class instantiation shortcut

  1. #1

    Thread Starter
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Resolved [RESOLVED] [2.0] Class instantiation shortcut

    Hi all,

    For example:

    vb.net Code:
    1. Dim wc As New System.Net.WebClient()
    2. Dim wc As Net.WebClient = New System.Net.WebClient()

    As the first line above is a shortcut for the second, is there an equivalent in C# for this or is this the only option?

    c# Code:
    1. System.Net.WebClient wc = new System.Net.WebClient();

    Thanks.

  2. #2
    Addicted Member effekt26's Avatar
    Join Date
    Nov 2006
    Posts
    138

    Re: [2.0] Class instantiation shortcut

    Quote Originally Posted by nmadd
    Hi all,

    For example:

    vb.net Code:
    1. Dim wc As New System.Net.WebClient()
    2. Dim wc As Net.WebClient = New System.Net.WebClient()

    As the first line above is a shortcut for the second, is there an equivalent in C# for this or is this the only option?

    c# Code:
    1. System.Net.WebClient wc = new System.Net.WebClient();

    Thanks.
    You could add 'using System.Net;' to the top of your page...

    Code:
    using System.Net;
    
    ...
    
    WebClient wc = new WebClient();
    but unsure of any other way....

    Cheers, Justin

  3. #3
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: [2.0] Class instantiation shortcut

    Quote Originally Posted by nmadd
    Hi all,

    For example:

    vb.net Code:
    1. Dim wc As New System.Net.WebClient()
    2. Dim wc As Net.WebClient = New System.Net.WebClient()

    As the first line above is a shortcut for the second, is there an equivalent in C# for this or is this the only option?

    c# Code:
    1. System.Net.WebClient wc = new System.Net.WebClient();

    Thanks.
    As far as I'm concerned, No.

  4. #4

    Thread Starter
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2.0] Class instantiation shortcut

    Thanks effekt, but it could've been any class. Was just looking for the shortened code.


    Thanks mar: I didn't think there was since the code converter I use spit out the same line regardless of what line of VB I pumped in.

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