奇怪的StringBuilder

king2003 2008-08-27 04:32:52
using System;
using System.Text;

public sealed class App
{
static void Main()
{
// Create a StringBuilder that expects to hold 50 characters.
// Initialize the StringBuilder with "ABC".
StringBuilder inlineCode = new StringBuilder();
StringBuilder sb = new StringBuilder("ABC", 50);
sb=inlineCode;
// Append three characters (D, E, and F) to the end of the StringBuilder.
sb.Append(new char[] { 'D', 'E', 'F' });

// Append a format string to the end of the StringBuilder.
sb.AppendFormat("GHI{0}{1}", 'J', 'k');

// Display the number of characters in the StringBuilder and its string.
Console.WriteLine("{0} chars: {1}", sb.Length, sb.ToString());

// Insert a string at the beginning of the StringBuilder.
sb.Insert(0, "Alphabet: ");

// Replace all lowercase k's with uppercase K's.
sb.Replace('k', 'K');

// Display the number of characters in the StringBuilder and its string.
Console.WriteLine("{0} chars: {1}", sb.Length, sb.ToString());
Console.WriteLine("{0} chars1111: {1}", inlineCode.Length, inlineCode.ToString());
}
}
inlineCode这个值怎么会跟着sb变化呀
...全文
105 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
king2003 2008-08-27
  • 打赏
  • 举报
回复
我明白了谢谢
danjiewu 2008-08-27
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 king2003 的回复:]
sb=inlineCode; 赋值以后,这两个变量的地址一样了
地址一样是哪个一样?和inlineCode 一样?
[/Quote]

sb=inlineCode之后sb和inlineCode指向了同一个StringBuilder对象,这样能明白了?
king2003 2008-08-27
  • 打赏
  • 举报
回复
sb=inlineCode; 赋值以后,这两个变量的地址一样了
地址一样是哪个一样?和inlineCode 一样?
lude8880 2008-08-27
  • 打赏
  • 举报
回复
sb=inlineCode; 你把inlinecode的指针传到sb上了,
换成 sb=inlinecode.toString(0;就成了
king2003 2008-08-27
  • 打赏
  • 举报
回复
可以这样理解?
bluepingguo 2008-08-27
  • 打赏
  • 举报
回复
sb=inlineCode; 赋值以后,这两个变量的地址一样了
lijin84100 2008-08-27
  • 打赏
  • 举报
回复
StringBuilder sb = new StringBuilder("ABC", 50);
sb=inlineCode;

是这一句的;问题吗,你设置断点测试一下,就知道了.
danjiewu 2008-08-27
  • 打赏
  • 举报
回复
sb=inlineCode;
这不就是同一个StringBuilder了吗?

110,531

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧