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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:56:54+00:00 2026-05-10T17:56:54+00:00

I have a String which I would like to modify in some way. For

  • 0

I have a String which I would like to modify in some way. For example: reverse it or upcase it.

I have discovered that the fastest way to do this is by using a unsafe block and pointers.

For example:

        unsafe          {             fixed (char* str = text)             {                 *str = 'X';             }         } 

Are there any reasons why I should never ever do this?

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T17:56:55+00:00Added an answer on May 10, 2026 at 5:56 pm

    The .Net framework requires strings to be immutable. Due to this requirement it is able to optimise all sorts of operations.

    String interning is one great example of this requirement is leveraged heavily. To speed up some string comparisons (and reduce memory consumption) the .Net framework maintains a Dictionary of pointers, all pre-defined strings will live in this dictionary or any strings where you call the String.intern method on. When the IL instruction ldstr is called it will check the interned dictionary and avoid memory allocation if we already have the string allocated, note: String.Concat will not check for interned strings.

    This property of the .net framework means that if you start mucking around directly with strings you can corrupt your intern table and in turn corrupt other references to the same string.

    For example:

             // these strings get interned         string hello = 'hello';         string hello2 = 'hello';          string helloworld, helloworld2;          helloworld = hello;         helloworld += ' world';          helloworld2 = hello;         helloworld2 += ' world';           unsafe         {             // very bad, this changes an interned string which affects              // all app domains.             fixed (char* str = hello2)             {                 *str = 'X';             }              fixed (char* str = helloworld2)             {                 *str = 'X';             }          }          Console.WriteLine('hello = {0} , hello2 = {1}', hello, hello2);         // output: hello = Xello , hello2 = Xello             Console.WriteLine('helloworld = {0} , helloworld2 = {1}', helloworld, helloworld2);         // output : helloworld = hello world , helloworld2 = Xello world   
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a mapping which maps two string into one string.
I have a string which is like this: this is "a test" I'm trying
I have the following string, which matches the following RegEx string. I would like
I have some strings that I would like to pattern match and then extract
I want to have a string variable for a PHP class, which would be
I have a char pointer which would be used to store a string. It
I have the string which that encoded in quoted-printable . How do I decode
I'm new to Javascript and would like to modify a text string by clicking
I have an ActiveRecord model that has a long string field. Actually, this string
I have a db model for which I would like to edit with multiple

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.