.net(关于字符串的相等问题[比较重要])
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestString
{
class Program
{
static void Main(string[] args)
{
string a = "hello";
string b = "h";
b +="ello";
string c = "hello";
if ((object)a == (object)b)
{
Console.WriteLine("True");
}
else
{
Console.WriteLine("False");
}
if ((object)a == (object)c)
{
Console.WriteLine("True");
}
else
{
Console.WriteLine("False");
}
}
}
}注,这属于.net内存对字符串的分配问题,如果是没有经过相加的字符串,如果内容相同地址也相同,即为同一区域。如果是组装以后才相等的,则重新分配内存!
浙公网安备 33010602011771号