Skip to content

Instantly share code, notes, and snippets.

@vaclavbohac
Created June 9, 2011 12:13
Show Gist options
  • Save vaclavbohac/1016619 to your computer and use it in GitHub Desktop.
Save vaclavbohac/1016619 to your computer and use it in GitHub Desktop.
Example v C# string interning.
using System;
using System.Text;
// Example of C# string interning.
// Created by Vaclav Bohac in 2011
class Test
{
public static void Main()
{
string foo = "Lipsum",
bar = "Lipsum";
string buz = new StringBuilder().Append("Li").Append("psum").ToString();
Console.WriteLine((Object) foo == (Object) bar); // True
Console.WriteLine((Object) foo == (Object) buz); // False
// ... but ...
Console.WriteLine(foo == buz); // True
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment