Click here to Skip to main content
15,881,898 members
Articles / Programming Languages / C#
Tip/Trick

LINQ to memory objects in the .NET Compact Framework

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
19 Dec 2010CPOL 15.1K   3   3
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
 
C#
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Standout IT Solutions(P) Ltd.
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralDooper Super Pin
jfriedman16-Dec-10 9:22
jfriedman16-Dec-10 9:22 
GeneralRe: Dooper Super Pin
SuhasHaridas13-Aug-12 0:16
SuhasHaridas13-Aug-12 0:16 
Generalcode Pin
vinuxlnt13-Dec-10 18:41
vinuxlnt13-Dec-10 18:41 
super

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.