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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:24:53+00:00 2026-05-14T01:24:53+00:00

I wanted to ask what is the idea behind the fact that System.String doesn’t

  • 0

I wanted to ask what is the idea behind the fact that System.String doesn’t contain parameterless constructor.

Because of this you cannot use this type when there is new() constraint.

UPDATE

Why do you think that new string() is useless and e.g. new int() is not useless. I really cannot see the difference. I really would like to be able to use a new() constraint on string, since what I’m expecting is String.Empty.

UPDATE2

I know that int is a value type and all value types have default parameterless constructor.
I was referring to @John Saunders answer (and similar answers) that were stating that saying new String() basically doesn’t do anything useful. So if new String() doesn’t mean anything useful what is so useful about new int()? I also understand that it is important for value types to have default parameterless constructors. What is more I think that it would be really nice for string to have a default parameterless constructor. Lack of a parameterless constructor means for me that an object simply cannot exist without a parameter that will initialize it. In my opinion string doesn’t need any parameter because it could be empty. I asked this question because I wanted to know if there is some important reason for string not having parameterless constructor or it’s just design or sth else.

UPDATE3

I guess it will be the last update since it looks more like a blog post than a question. In java strings are also immutable and new String() is perfectly legal. However, documentation for parameterless constructor says:

Initializes a newly created String
object so that it represents an empty
character sequence. Note that use of
this constructor is unnecessary since
Strings are immutable.

UPDATE4

Ok, last update 😉 I have to agree with John Saunders. I was using code that had new() constraint and it worked nicely for custom classes. Then, my colleague need to change the code for ints and it was ok. Then change it for string and we had a problem. When I now think about it I guess the code we are using needs to be changed to reflect that we need scalar types not classes that have parameterless constructor. All that said, I still think it’s a bit inconsisent that you can write new int() and you are unable to write new string() (yes, I understand that int is a value type ;)). Thanks for all your answers!

Thanks in advance for help.

  • 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-14T01:24:53+00:00Added an answer on May 14, 2026 at 1:24 am

    If you could use

    string s = new string();
    

    What would you do with it? Strings are immutable.


    Some readers have thought I was saying that a parameterless string constructor would be useless. That’s not what I meant. I meant that the empty string created from such a constructor would be useless in the rest of the code.

    Keep in mind what the OP said he wanted to do:

    public void SomeMethod<T>() where T : new()
    {
        var t = new T();
        // Do _what_ now?
    }
    
    // Call:
    SomeMethod<string>();
    

    I don’t see what you could do with t after it was constructed.

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

Sidebar

Related Questions

I need to develop a file indexing application in python and wanted to know

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.