system.web.ui.webcontrols.textbox不包含" lines"的定义。

时间:2016-03-29 08:12:06

标签: c# html css asp.net

我正在尝试计算文本文件中的重复单词,我收到此错误:

  

system.web.ui.webcontrols.textbox不包含"行" ...

的定义

到目前为止,我记得.lines的命名空间是system.windows.forms ...而且我已经使用过了......所以如果有人能指导我出错的地方......

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void Click_Click(object sender, EventArgs e)
    {
        TextBox1.Lines =File.ReadAllLines("D:\\mun.txt")
        Regex regex = new Regex("\\w+");

        var frequencyList = regex.Matches(TextBox1.Text)
                                 .Cast<Match>()
                                 .Select(c => c.Value.ToLowerInvariant())
                                 .GroupBy(c => c)
                                 .Select(g => new { Word = g.Key, Count = g.Count() })
                                 .OrderByDescending(g => g.Count)
                                 .ThenBy(g => g.Word);

        Dictionary<string, int> dict = frequencyList.ToDictionary(d => d.Word, d => d.Count);

        foreach (var item in frequencyList)
        {
            Label1.Text =Label1.Text+item.Word+"\n";
            Label2.Text = Label2.Text+item.Count.ToString()+"\n";
        }
    }
}

1 个答案:

答案 0 :(得分:2)

行而不是行。您需要读取的数组的长度来设置Rows属性。由于您已经开始使用ReadAllLines,因此您需要通过在单个字符串中连接行来构建整个内容。 HTML正在使用<br />来显示新行

protected void Click_Click(object sender, EventArgs e)
{
    string[] lines = File.ReadAllLines("D:\\mun.txt");
    var content = String.Join(System.Environment.NewLine, lines);
    TextBox1.Rows = lines.Length;
    TextBox1.Text = content;

    Regex regex = new Regex("\\w+");
    var frequencyList = regex.Matches(content)
        .Cast<Match>()
        .Select(c => c.Value.ToLowerInvariant())
        .GroupBy(c => c)
        .Select(g => new { Word = g.Key, Count = g.Count() })
        .OrderByDescending(g => g.Count)
        .ThenBy(g => g.Word);
    Dictionary<string, int> dict = frequencyList.ToDictionary(d => d.Word, d => d.Count);

    foreach (var item in frequencyList)
    {
        Label1.Text = Label1.Text + item.Word + "<br />";
        Label2.Text = Label2.Text + item.Count.ToString() + "<br />";
    }
}