Note that there are some explanatory texts on larger screens.

plurals
  1. POLinqy no matchy
    text
    copied!<p>Maybe it's something I'm doing wrong. I'm just learning Linq because I'm bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control.</p> <p>usage: enter text into textbox, click button. program lets you select a file to match the textbox value against and returns matches in label control.</p> <p>code:</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace LinqTests { public partial class Form1 : Form { public Form1() { InitializeComponent(); } protected internal String[] Content; public String Value; private void button1_Click(object sender, EventArgs e) { Value = textBox1.Text; OpenFileDialog ofile = new OpenFileDialog(); ofile.Title = "Open File"; ofile.Filter = "All Files (*.*)|*.*"; if (ofile.ShowDialog() == DialogResult.OK) { Content = File.ReadAllLines(ofile.FileName); IEnumerable&lt;String&gt; Query = from instance in Content where instance == Value orderby instance select instance; foreach (String Item in Query) label1.Text += Item + Environment.NewLine; } else Application.DoEvents(); ofile.Dispose(); } } } </code></pre> <p><b>The Problem</b> What I have above works perfectly, except for one thing. I have a file that I check against which contains the following text:</p> <p>File: <hr> jason<br> is<br> the<br> funniest<br> person<br> in<br> the<br> world<br> jason<br> jason<br> jason<br> pezzimenti<br></p> <p>... And it never, ever returns "jason". but it will always return any other word in there.</p> <p>I'm guessing that it doesn't return a match if there is more that one of the same match?</p> <p>Would I be correct in saying so? And is this how it's supposed to be? And how would you suggest I make it always return a match no matter how many of the same matches there are. I mean I would have thought that it would return the following output, based on the code above... isn't that what the foreach(Item in Query) is for?, when i type "jason" into the textBox1:</p> <p>jason<br> jason<br> jason<br> jason</p> <p>..but it doesn't return any jasons :(</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload