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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:01:26+00:00 2026-06-04T10:01:26+00:00

In Class A(What will output the List if it is not empty): private List<int>

  • 0

In Class A(What will output the List if it is not empty):

private List<int> _myList = new List<int>
public List<int> MyList {get{return _myList;} set{_myList = value;}}

In Class B:

public bool MyClassBMethod(stuff)
{
     //stuff
     try{
          something
     }
     catch(Exception){
         ClassA.MyList.Add(stuff);
         return false;
     }
     return true;
}

Is editing a List like this bad practice? Or is it okay?

Edit: I am only adding to the list as such when my method needs to return something else(bool, object, string, etc).

  • 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-04T10:01:28+00:00Added an answer on June 4, 2026 at 10:01 am

    In general, a class should be responsible for managing its own internal state. By giving full public access to a member like this, you are basically saying that Class A is giving up responsibility of that part of its state. It cannot make assumptions about what _myList contains because anyone could change that at any time.

    Whether that’s good or not depends on what your intent is, but it certainly runs contrary to the ideas of decoupling and encapsulation. Again, whether you want decoupling and encapsulation is up to you.

    A better question would be to determine what sort of decoupling between classes A and B would be most beneficial to your design, and then you’d be able to decide what member to expose and how.

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

Sidebar

Related Questions

My situation is a follows: There is some class MyList that will probably get
I would like to localize my c# class library The library will output a
If you have a large class that executes after output(headers/text) is already sent, will
I'm creating a class that will have one public method, which returns a value
I'm serialising a List of a class and I'm not happy about the generated
In C#, if you do this, it will compile: namespace Name { public class
there is a simple class called User and List of its objects public class
I am new to XStream I have following DTO @XStreamAlias(outline) public class OutlineItem implements
I'd like to be able to determine what class will be called given an
I have written a class that will handle internal logging in my application. Now

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.