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

The Archive Base Latest Questions

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

Thanks everyone for your answers. The one issue I am having though is when

  • 0

Thanks everyone for your answers. The one issue I am having though is when I print the value of each of the variables in the methods Helpdesk and IT, it does not print “help”, “hellp123”, and “Welcome Helpdesk!” rather prints “admin”, “admin” and “Welcome”. THe case is same for the method IT.

public class Login
{
    public string[] array = new string[3];
    public string UserName;
    public string Password;
    public string Message;
}

public Login
{
   UserName = array[0] = "admin";
   Password = array[1] = "admin"; 
   Message = array[2] = "Welcome";

}

public void Helpdesk
{
    UserName = "help";
    Password = "help123";
    Message = "Welcome Helpdesk!";
    Console.WriteLine(UserName); //still prints admin
    Console.WriteLine(Password); // still prints admin
    Console.WriteLine(Message); // still prints Welcome
}
public void IT
{
    UserName = "it";
    Password = "Pa$$w0rd";
    Message = "Welcome IT!";

}

Can I use the same variable names: UserName, Password and Message for methods: Helpdesk and IT for the same class Login like below?
public class Login
{
public string[] array = new string[3];
public string UserName;
public string Password;
public string Message;
}

public Login
{
   UserName = array[0] = "admin";
   Password = array[1] = "admin"; 
   Message = array[2] = "Welcome";  
}

public void Helpdesk
{
    UserName = "help";
    Password = "help123";
    Message = "Welcome Helpdesk!";
}
public void IT
{
    UserName = "it";
    Password = "Pa$$w0rd";
    Message = "Welcome IT!";

}
  • 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-23T04:27:48+00:00Added an answer on May 23, 2026 at 4:27 am

    The variables you talk of are fields in the class. The are confined to that class. If you create new variables with the same name, but not inside the same class (like you do above), that is allowed. If you do it inside your class, it will shadow the field, which is considered a bad practice.

    Note: if you only assign to the field from inside the class (like you may imply in your question, but the code is not complete), you simply change its value.

    public class Login
    {
        public string Message;
        public string Name;
    
    
        public void Test()
        {
           Message =  "Welcome";  // changes field, same as this.Message = ...
           var Name = "Me";       // does not change field, hides field Name
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks everyone for taking the time to read this. I have styled my navigation
Thanks to everyone out there helping newbies like me. So far I have this:
Hello and thanks to everyone for reading my question. I've been working on a
This is my first question. Thanks to everyone who contributes to this site, it's
EDIT AGAIN: the solution was probably different from my original question. Thanks everyone very
i have got this HTML code: <select name=audience[8787330733][value]> <option value=></option> <option value=80>Everyone</option> <option selected=1
Updated question to reflect answers and my research Thanks casablanca and wallyk for answering.
Right first of I would like to thank everyone for helping me out on
First, I would to thank everyone for all the help they provide via this
thank you everyone for helping me out with this. i am new to ruby

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.