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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:11:48+00:00 2026-05-11T16:11:48+00:00

I am currently reading C# in Depth by Jon Skeet and have been reading

  • 0

I am currently reading C# in Depth by Jon Skeet and have been reading about value and reference types.

It got me thinking about the cost of using value types as method parameters due to that value being copied when passed. While this cost is not much when considering integers, what if those value parameters were strings which got passed around numerous times.

Would there be a benefit to using say a StringBuilder class and passing it instead of a string type?

If you considered that the string was long, say 1024 characters, and was passed around even just a few times between methods, contrast that with a StringBuilder with the same value which would end up passing the value of the reference being 4 or 8 bytes each time, you could have a considerable performance inprovement.

This question may also highlight a vital piece of understanding I may be missing regarding the String type, feel free to point this out where required.

Also, what what impact would this have on garbage collection regarding the strings in each instance?

Edit: Apparently I did forget one vital piece of information about strings which renders the question null and void. Thanks grover.

  • 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-11T16:11:48+00:00Added an answer on May 11, 2026 at 4:11 pm

    String is not a value type, they’re just immutable objects.

    Passing a string around incurs the same cost as any other object: The size of its reference, which is 4 bytes on Win32.

    On additional note: The value type semantics (by value passing) can be implemented by the compiler in an optimized way. I haven’t looked at how the MS JIT is doing it, but it certainly can still send only a pointer to it and require the target to make a copy on write.

    This is what we’re going to do in the Managed Operating System Alliance JIT/AOT compiler.

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

Sidebar

Related Questions

I'm currently reading Jon Skeet's C# in depth 2nd edition and the following question
Im currently reading Spring in Action 3rd edition, and have been experimenting with Spring
im currently reading a book about programming Android and there is a nice little
Context I'm currently reading about Clojure's implementation of monads: org.clojure/algo.monads Intuitively, reduce looks like
I'm currently reading Dive Into Python by Mark Pilgrim, and have gotten to the
I am currently reading a book on Javascript by Pragmatic, and I'm confused about
I am currently reading an Algorithm Textbook which is in Java. I have managed
I am currently reading about SWT. There is often written, that Eclipse as an
Currently reading quite a heavy WCF book. I have used it myself in production
I'm currently reading up on Covariance and Contravariance in C#. All examples have details

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.