您的位置:首页 > 其它

.net(关于字符串的相等问题[比较重要])

2012-07-10 08:45 295 查看
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内存对字符串的分配问题,如果是没有经过相加的字符串,如果内容相同地址也相同,即为同一区域。如果是组装以后才相等的,则重新分配内存!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: