Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8926333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:56:55+00:00 2026-06-15T07:56:55+00:00

I am trying to use a privately declared variable/object within a class, from a

  • 0

I am trying to use a privately declared variable/object within a class, from a shared function within that same class.

My main goal is to be able to access the shared function outside of the class, but not the variables, seeing as they are private. I do not think setting all variable/object declarations as “shared” would be an elegant solution.

Here is a snippet for better examination:

Module main
    Sub Main()
        MsgBox(xTest.xMain)
    End Sub
End Module

Class xTest
    Private WC As New Net.WebClient()
    Shared Function xMain() As String
        Return WC.DownloadString("http://example.com")
    End Function
End Class

How would I go about doing this, properly of course.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:56:56+00:00Added an answer on June 15, 2026 at 7:56 am

    I suspect you’re confused about the meaning of Shared. This is orthogonal to Private/Public/etc.

    Shared means “specific to the type, not to any instance of the type”. Your Shared function can’t use WC because it doesn’t have an instance of xTest to find the specific WC variable for. Imagine it was a name variable instead – it’s like asking a Person class “What’s your name?” when instead each individual Person instance has a name.

    You should think carefully for each member (whether it’s a function or a variable) whether it’s logically Shared or not.

    See the MSDN page on shared members for more details – although I dislike the description used there. “… shared by all instances of a class …” sounds like there has to be an instance in the first place. There doesn’t – it’s just that the member is associated with the type itself. A shared variable can be used even if no instances of the class are ever created.

    (As an aside, I probably wouldn’t keep hold of a WebClient as a field in the first place. WebClient is designed to be created, used, then discarded. I’d also suggest changing your names to follow .NET naming conventions.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am trying to make a global class that I can use in
I am in Windows 7 x64, and trying to use the same Event object
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
Normally, I've seen prototype functions declared outside the class definition, like this: function Container(param)
I am trying to use the Rails *shopify_app* gem with a private API key.
I'm trying to use a PEM(X.509) certificate (stored in a privateKey.pem file on disk)
i'm trying use facebook API to upload photo in my fan page. I downloaded
I am trying use gem tire to search in my application. I have tables
I was trying use a set of filter functions to run the appropriate routine,
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.