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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:16:34+00:00 2026-06-10T22:16:34+00:00

I have one class file JobSeekerBO it’s has variable string _username = string.Empty; string

  • 0

I have one class file JobSeekerBO it’s has variable

   string _username = string.Empty;
   string _password = string.Empty;

and i set value as below

public string Username
{
    get { return _username; }
    set { _username = value; }
}

public string Password
{
    get { return _password; }
    set { _password = value; }
}

but problem is that that variable i access in another class file class1.cs i create object of that class file

JobSeekerBO objBO = new JobSeekerBO();

but i can’t access Username and Password in class1.cs class file from my JobSeekerBO.cs file

I also try to make that variable public as per below

public string _username = string.Empty;
public string _password = string.Empty;

same class file varible without public access modifier we can access in file1.aspx.cs file

So please tell me how to access variable and method of one .cs file to another .cs file.

Page Code

  • 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-10T22:16:36+00:00Added an answer on June 10, 2026 at 10:16 pm

    You can not access _username and _password outside your class because they are private by default. That means they are accessible only within the body of the class. But you have the Public properties which sets and gets values on these fields. So you should use those public Properties.

    JobSeekerBO objBO = new JobSeekerBO();
    objBo.Username="someusername";
    objBo.Password="myPassword";
    

    Assuming your class look like this

    public class JobSeekerBO
    { 
       string _username = string.Empty;
       string _password= string.Empty;      
    
       public string Username
       {
            get { return _username; }
            set { _username = value; }
       }        
       public string Password
       {
            get { return _password; }
            set { _password = value; }
       }    
    }
    

    Generally, you should use fields only for variables that have private
    or protected accessibility. Data that your class exposes to client
    code should be provided through methods, properties and indexers.

    More about class fields here in msdn

    EDIT: After looking at your code.

    You are trying to set the Public property value in a wrong place. You can not do it there. You should do it in a method ( even in your Constructor is fine).

    public class MailRepositary
    {
      JobSeekerBO objBO = new JobSeekerBO();
      public MailRepositary()
      {
          objBo.UserName="works from constructor";
      }
      public void SomeMethod()
      {
          objBo.UserName="works from method also";
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one class, called A, and it has it's own header file. Then
I used to have one class for one file. For example car.cs has the
I have one class with some constant value like below : class MyClass {
i make one class file for jar. and this class have use wurfl. and
i have a really basic java program just one .java/.class file (.java uncompiled .class
In my C# codebehind file(.cs), I have just one class and it is derived
In one class I have a library project with a file class1 with namespace
I have a large-ish project that contains one class that reads from a file
I have one class. Class First { private Second second; public First(int num, String
I have one map within one header file class: class One { // code

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.