Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

LINQ to memory objects in the .NET Compact Framework

0.00/5 (No votes)
19 Dec 2010 1  
LINQ to memory objects in the .NET Compact Framework
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;
        }
    }
}
 
//Linq form 

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;             
        }
    }
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here