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

  • Home
  • SEARCH
  • 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 6157491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:47:43+00:00 2026-05-23T20:47:43+00:00

Suppose I my project contains a Form and a Class. I would like to

  • 0

Suppose I my project contains a Form and a Class. I would like to create a variable that can be accessed by both the Form and the class. In VB6 I could create a public variable in the (module / class), and easily access it like so:

VB6 Example

[Module code]

Public string_name as string

[/Module code]

[Form Code]

string_name = "test data"
MsgBox(string_name) ' Returns "test data"

[/Form Code]

How could I produce the above functionality with C#? I’m assuming I’d have to create a public class, but I’m not sure of the best way to declare public variables.

thank you,

Evan

  • 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-05-23T20:47:43+00:00Added an answer on May 23, 2026 at 8:47 pm

    You can do the same in c# (expose a field as public), though that is not good practice.

    Use properties instead:

    // public string property
    public string string_name { get; set; }
    
    // within class    
    string_name = "test data";
    MsgBox(string_name); 
    
    // from another class
    myClassInstance.string_name = "other test data";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let us suppose we are going to start new project - application that contains
Suppose I have a solution inside a TFS collection that contains 3 projects. Ho
Suppose you want to throw Exception like this: 'Project with the provided ID cannot
Suppose, I have an opensource project that depends on some library, that must be
Suppose I have an model object Event that contains a Venue . When I
Suppose my project directory has 2 sub-directories A and B, A directory contains: A.h
Suppose you have a TFS collection with a Samples project that contain your Visual
I have several somewhat separate programs, that conceptually can fit into a single project.
I have an Android Library Project that contains several styles/themes defined in its styles.xml
I'm trying to setup a project that contains commons apps (projectA) to be shared

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.