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

Related Questions

I have this class called Table: class Table { public string Name { get
I have a class Application that my global.asax inherits from. The class has this
I have a class that looks like this public class SomeClass { public SomeChildClass[]
How can I launch an event that has accessors like this : public event
I have this class. public class Foo { public Guid Id { get; set;
I have a class like this: public class Stretcher : Panel { public static
I have a class like this: public class myClass { public List<myOtherClass> anewlist =
This is probably not possible, but I have this class: public class Metadata<DataType> where
I have a class which looks something like this: public class Test { private
I've implemented a class that looks like this interface: [ImmutableObject(true)] public interface ICustomEvent {

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.