Language-Integrated Query (LINQ) adds general-purpose query facilities to the .NET Compact Framework that apply to various sources of information such as relational databases, XML data, and in-memory objects,
Here we define the LINQ to memory objects, we use list data type as the memory object to hold the data.
Entity.cs Class
using System;
using System.Collections.Generic;
using System.Linq;
namespace LINQ_test
{
public class entity
{
public string name
{
get;
set;
}
}
}
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace LINQ_test
{
public partial class Linq : Form
{
List<entity> li = new List<entity>();
public Linq()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
entity er= new entity();
er.name = textBox1.Text;
li.Add(er);
textBox1.Text = "";
ArrayList Alist = new ArrayList();
var varlinq = from p in li where p.name.Length < 4
select p;
foreach (var data in varlinq)
Alist.Add(data);
dataGrid1.DataSource = Alist;
}
private void button2_Click(object sender, EventArgs e)
{
ArrayList Alist = new ArrayList();
var varlinqnext = from p in li
select p;
foreach (var data in varlinqnext)
Alist.Add(data);
dataGrid1.DataSource = Alist;
}
}
}
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.