Click here to Skip to main content
15,892,809 members
Articles / Programming Languages / C#

Inside C#, Second Edition: String Handling and Regular Expressions Part 1

Rate me:
Please Sign up or sign in to vote.
4.94/5 (69 votes)
14 May 200217 min read 725.4K   2.2K   232  
This article will examine the String class, some of its simple methods, and its range of formatting specifiers.
using System;

namespace StringInterning
{
	class StringInterningApp
	{
		public class Thing
		{
			private int i;
			public Thing(int i) { this.i = i; }
		}

		[STAThread]
		static void Main(string[] args)
		{
			Thing t1 = new Thing(123);
			Thing t2 = new Thing(123);
			Console.WriteLine(t1 == t2);	// False

			string a = "Hello";
			string b = "Hello";

			Console.WriteLine(a == b);		// True

			string c = String.Copy(a);
			Console.WriteLine(a == c);		// True
			Console.WriteLine((object)a == (object)c);	// False

			Console.WriteLine((object)a == (object)b);	// True
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) Microsoft
United States United States
I manage the strategy for the Azure Management Experience documentation at Microsoft. Those technologies include Open-Source DevOps (Terraform, Ansible, Jenkins), Azure PowerShell, and Azure CLI.

Comments and Discussions