textBox1.lines.Take(1)如何转化成字符串。
可以这样写吗?
if(textBox1.lines.Take(1)==textBox2.lines.Take(1))
{
   ……
}

解决方案 »

  1.   

    用First。if(textBox1.lines.First()==textBox2.lines.First())
      

  2.   


                TextBox text = new TextBox();
                text.Lines=new string[]{"1","2","3","4"};
                string xstr = text.Lines.Take(1).FirstOrDefault();
      

  3.   

    如果textBox内容有很多行怎么办呢 我想进行逐行比较
      

  4.   

     TextBox text = new TextBox();
     text.Lines = new string[] { textBox1.Text };
     string xstr = text.Lines.Take(1).FirstOrDefault();
     label1.Text = xstr;就可以得到文本了,然后再比较。谢谢Chinajiyong
      

  5.   

    逐行比较直接用text.Lines[n],n为循环变量就可以了,还用什么Linq呀,浪费、增加复杂度、降低效率。
      

  6.   

      TextBox text = new TextBox();
                
      text.Lines = new string[] { textBox1.Lines.ElementAt(0) };//控制行数,定第一行或第n行
                
      string xstr = text.Lines.Take(1).FirstOrDefault();//获取锁定的行内容
      label1.Text = xstr;