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 7064415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:49:54+00:00 2026-05-28T04:49:54+00:00

I have a class that requests that when called a string is sent when

  • 0

I have a class that requests that when called a string is sent when requesting / initializing it.

class Checks
{
    public Checks(string hostname2)
    {
        // logic here when class loads

    }

    public void Testing()
    {
        MessageBox.Show(hostname2);
    }
}

How would it be possible to take the string “hostname2”) in the class constructor and allow this string to be called anywhere in the “Checks” class?

E.g. I call Checks(hostname2) from the Form1 class, now when the Checks class is initialized I can then use the hostname2 string in my Checks class as well

  • 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-28T04:49:55+00:00Added an answer on May 28, 2026 at 4:49 am

    Declare a member inside the class and assign the value you passed to the member inside the constructor:

    class Checks
    {
        private string hostname2;
    
        public Checks(string hostname2)
        {
           this.hostname2 = hostname2; // assign to member
        }
    
        public void Testing()
        {
            MessageBox.Show(hostname2);
        }
    }
    

    If you also need to have outside access, make it a property:

    class Checks
    {
        public string Hostname2 { get; set; }
    
        public Checks(string hostname2)
        {
           this.Hostname2 = hostname2; // assign to property
        }
    
        public void Testing()
        {
            MessageBox.Show(Hostname2);
        }
    }
    

    Properties start with a capital letter by convention. Now you can access it like this:

    Checks c = new Checks("hello");
    string h = c.Hostname2; // h = "hello"
    

    Thanks to Andy for pointing this out: if you want the property to be read-only, make the setter private:

    public string Hostname2 { get; private set; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in AS3, I have an external class ImageLoader, that loads an image upon request.
I have a class that looks like this public class SomeClass { public SomeChildClass[]
I have an activity class that gets a JSON string by making a query.
I have a Class called MyMailSender that binds to the asp.net controller called EmailController.
I have a class called UserContext that tracks the activities of a given user
In Restlet you have a class called SecretVerifier with an abstract method verify(String identifier,
I have created a new class called Get_WebPage1 and init I have extends that
I have a class that builds a request based on a few passed in
I have an HTTP Request Dispatcher class that works most of the time, but
I have class that represents users. Users are divided into two groups with different

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.