对字符串clientNameStr使用“替换”导致“未找到对象引用”错误。C#替换导致未找到对象引用错误
// Get client name
clientName = currentUser.GetValue("ClientName");
string clientNameStr = (string)clientName;
string clientURLStr = string.Empty;
clientURLStr = clientNameStr.Replace(' ', '-');
// clientURLStr = "ST9215-Stanic-Parts-Ltd";
如果我在注释掉字符串替换(并注释掉现有的),它工作正常,所以它必须是与替换功能,但什么?有两种“和”引号试了一下,相同的结果。
任何帮助,将不胜感激。
谢谢,奥利。
确定'currentUser.GetValue( “CLIENTNAME”)'是不是返回null? – Rawling 2012-03-20 11:59:03
[在.NET中是什么是NullReferenceException?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net) – 2012-03-20 12:00:02
使用调试器进行调试 – 2012-03-20 12:14:28