System.String Vs System.Text(programming360.blogspot.com)

submitted by syedtayyabalisyedtayyabali(135) 2 years, 6 months ago

Strings of type System.String are immutable (read-only) in .NET because its value cannot be modified once it has been created. That means any change to a string causes the runtime to create a new string object and abandon the old one. That happens invisibly. Following code allocates three new strings in memory: Example: string str = "This is Programming360 Blog. "; str += "It educate technical communities. "; str += "It believes, one concept at a time..."; Only the last string has a reference; the other two will be disposed of during garbage collection. Avoiding these types of temporary strings helps avoid unnecessary garbage collection, which improves performance. There are several ways to avoid temporary strings: * Use the String class's Concat, Join, or Format methods to join multiple items in a single statement. * Use the StringBuilder class to create dynamic (mutable) strings. The StringBuilder solution is the most flexible because it can span multiple statements. The default constructor creates a buffer 16 bytes long, which grows as needed. You can specify an initial size and a maximum size if you like. Example: System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("This is Programming360 Blog. "); sb.Appen("It educate technical communities. ";); sb.Appen("It believes, one concept at at time...");

add a comment |category: |Views: 24

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

No comments so far

information Login or create an account to comment on this story