在C#中使用字符串的表 [英] Table using string in c#

查看:93
本文介绍了在C#中使用字符串的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在c#中使用字符串在html中创建表?

is it possbile to create a table in html using string in c#??

 public void Paging(ref StringBuilder strHtml, int pageIndex, int pagingCount, int rowCount, string listView, string controller, int position)
        {

            try
            {
                strHtml.Append("<table class='Dsply' border='0' cellspacing='0' 
}
cellpadding='0'><tr><th>");





Instead of the string builder if i use a string will i be able to create one table?

推荐答案

您可以使用字符串或StringBuilder来创建表,而不是使用字符串构建器. string的效率要低得多,因为每次向其添加新数据时,它都会创建一个新字符串并返回-未修改旧字符串(因为字符串为immutable-创建后无法更改). StringBuilder是不同的-可以更改它们,直到空间用完为止,这时它们将被更大的替换.这就是为什么将字符串用于这种操作被认为是一个坏主意的原因.
如果确实使用字符串,则需要使用不同的语法:
You can do it using either a string or a StringBuilder, but a string is a lot less efficient because each time you add new data to it, it creates a new string and returns that - the old string is untouched (because strings are immutable - the cannot be changed once they are created). StringBuilders are different - they can be changed, until they run out of space, at which point they are replaced with a bigger one. That is why it is considered a bad idea to use a string for this kind of operation.

If you do use a string, then you need a different syntax:
strHtml = strHtml + "new string";




or

strHtml += "new string";


字符串类没有Append方法.

如果使用StringBuilder,则不需要ref参数-如果要更改"字符串,则不需要此参数.

就我个人而言,我放弃了ref参数,使用StringBuilder并将其作为方法的结果返回:


The string class does not have an Append method.

If you use a StringBuilder, you do not need the ref parameter - you do if you want to "change" the string.

Personally, I would ditch the ref parameter, use a StringBuilder and return it as the result of the method anyway:

public StringBuilder Paging(StringBuilder strHtml, int pageIndex, int pagingCount, int rowCount, string listView, string controller, int position)
   {
   strHtml.Append("<table class="Dsply" border="0" cellspacing="0" cellpadding="0"><tr><th>");
   return strHtml;
   }</th></tr></table>


这篇关于在C#中使用字符串的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆