我正在尝试使用html代码创建一个字符串,以使用它来呈现购物车
DateTimeZone
第二次在循环中我收到错误' System.OutOfMemoryException'在mscorlib.dll中 我减少了字符串的大小,它工作。任何想法?
答案 0 :(得分:2)
您使用StringBuilder
,但也创建了太多字符串。
这样做:
sb.Append("<div class=\"ibox-content\">"+
"<div class=\"table-responsive\">"+
"<table class=\"table shoping-cart-table\">"+
......
您只追加一次,但使用+
(连接)可以创建许多新字符串并获得OutOfMemoryException
。
上面的代码应该更改为类似的内容(使用StringBuilder.Append()
追加每一行):
sb.Append("<div class=\"ibox-content\">");
sb.Append("<div class=\"table-responsive\">");
sb.Append("<table class=\"table shoping-cart-table\">");
...