111,120
社区成员
发帖
与我相关
我的任务
分享Console.Write("a" + "b" + "c");
Console.Write(String.Concat("a", "b", "c"));Console.Write("abc");
Console.Write("a" + "b" + "c");public StringBuilder Append(string value)
{
if (value != null)
{
string stringValue = this.m_StringValue;
IntPtr currentThread = Thread.InternalGetCurrentThread();
if (this.m_currentThread != currentThread)
{
stringValue = string.GetStringForStringBuilder(stringValue, stringValue.Capacity);
}
int length = stringValue.Length;
int requiredLength = length + value.Length;
if (this.NeedsAllocation(stringValue, requiredLength))
{
string newString = this.GetNewString(stringValue, requiredLength);
newString.AppendInPlace(value, length);
this.ReplaceString(currentThread, newString);
}
else
{
stringValue.AppendInPlace(value, length);
this.ReplaceString(currentThread, stringValue);
}
}
return this;
}
public static string Concat(string str0, string str1)
{
if (IsNullOrEmpty(str0))
{
if (IsNullOrEmpty(str1))
{
return Empty;
}
return str1;
}
if (IsNullOrEmpty(str1))
{
return str0;
}
int length = str0.Length;
string dest = FastAllocateString(length + str1.Length);
FillStringChecked(dest, 0, str0);
FillStringChecked(dest, length, str1);
return dest;
}
private static unsafe void FillStringChecked(string dest, int destPos, string src)
{
int length = src.Length;
if (length > (dest.Length - destPos))
{
throw new IndexOutOfRangeException();
}
fixed (char* chRef = &dest.m_firstChar)
{
fixed (char* chRef2 = &src.m_firstChar)
{
wstrcpy(chRef + destPos, chRef2, length);
}
}
}
private static unsafe void wstrcpy(char* dmem, char* smem, int charCount)
{
if (charCount > 0)
{
if ((((int) dmem) & 2) != 0)
{
dmem[0] = smem[0];
dmem++;
smem++;
charCount--;
}
while (charCount >= 8)
{
*((int*) dmem) = *((uint*) smem);
*((int*) (dmem + 2)) = *((uint*) (smem + 2));
*((int*) (dmem + 4)) = *((uint*) (smem + 4));
*((int*) (dmem + 6)) = *((uint*) (smem + 6));
dmem += 8;
smem += 8;
charCount -= 8;
}
if ((charCount & 4) != 0)
{
*((int*) dmem) = *((uint*) smem);
*((int*) (dmem + 2)) = *((uint*) (smem + 2));
dmem += 4;
smem += 4;
}
if ((charCount & 2) != 0)
{
*((int*) dmem) = *((uint*) smem);
dmem += 2;
smem += 2;
}
if ((charCount & 1) != 0)
{
dmem[0] = smem[0];
}
}
}
//建议楼主多去查阅MSDN
//reflector
int i;
string s = "";
for (i = 0; i < 100; i++)
{
s = s + i.ToString();//此处的ToString()是多余的
}
Console.Write(s);
s = "";
for (i = 0; i < 100; i++)
{
s = s + i.ToString();//同上
}
Console.Write(s);
string s = "";
for (int i = 0; i < 100; i++)
{
s += i.ToString();
}
Console.Write(s);
s = "";
for (int i = 0; i < 100; i++)
{
s = String.Concat(s, i.ToString());
}
Console.Write(s);
//reflector
int i;
string s = "";
for (i = 0; i < 100; i++)
{
s = s + i.ToString();
}
Console.Write(s);
s = "";
for (i = 0; i < 100; i++)
{
s = s + i.ToString();
}
Console.Write(s);
Console.Write("a" + "b" + "c");
Console.Write(String.Concat("a", "b", "c"));//如果参数不是字符串!会先将其转换成字符串再执行操作
//你那样看其实看不到什么