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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:19:14+00:00 2026-05-12T06:19:14+00:00

I have a class, this class can be empty. This class has only public

  • 0

I have a class, this class can be empty. This class has only public properties of type String. When this class is in an empty state, that means that all properties have the value of String.Empty.

1) With a public static field, the properties of Class.Empty can be modified.

2) I don’t see that a public static property getter should return a new empty object (set all fields to Empty manually) every time. I consider that bad practice.

3) An alternate solution is to implement your own Class.IsNullOrEmpty(Class obj).

4) A non-static public boolean property obj.IsEmpty.

In the other class where this class is being used, the property will never be null. The other class is returned from a method (of yet another class,) which properly initializes it.

The only case the property might be null, is if it’s newed outside that method, which then causes it to be in an invalid state anyway.

  • 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-12T06:19:14+00:00Added an answer on May 12, 2026 at 6:19 am

    1 and 2 conflict, basically.

    Either your type is immutable, in which case you can return a reference to the same instance every time… or it’s mutable, in which case you have to return a reference to a new object each time.

    The reason string.Empty is fine is precisely because string is immutable.

    Does your type have to be mutable?

    EDIT: Based on your comment, it sounds like the properties shouldn’t have setters at all. Instead, the values should be passed into the constructor, and stored in readonly fields.

    At that point your type is immutable, so you can expose either a public field or property which always returns the same value, i.e.

    private static readonly MyType empty = new MyType("", ""); // Or whatever
    public static MyType Empty { get { return empty; } }
    

    or

    public static readonly MyType Empty = new MyType("", "");
    

    You don’t need to worry about anyone setting any properties, because you haven’t got any setters…

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

Sidebar

Ask A Question

Stats

  • Questions 172k
  • Answers 172k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer SELECT p.name AS prize, c.name AS contestant FROM contestants c… May 12, 2026 at 2:27 pm
  • Editorial Team
    Editorial Team added an answer RPAL compiles down to lambda expressions, which can then be… May 12, 2026 at 2:27 pm
  • Editorial Team
    Editorial Team added an answer n.b. see 2018 update at the bottom I recommend against… May 12, 2026 at 2:27 pm

Related Questions

I have seen a codebase recently that I fear is violating alignment constraints. I've
I have an Events table whose goal is to store actions done by web
OK, I know what you're thinking, "why write a method you do not want
I'm playing around with SubSonic 3.0 at the moment, and it looks really straight-forward

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.