Custom SQL queries using Linq

Database Schema
student
id int, auto_increment, primary key
fname char(20)
lname char(20)
age int

grade
id int, auto_increment, primary key
studentid int,
grade int

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ListBox ID="gradesLB" runat="server"></asp:ListBox>
    </div>
    </form>
</body>
</html>

Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    class GradeClass
    {
        private int _grade;
        private int _id;

        public int grade
        {
            get
            {
                return this._grade;
            }
            set
            {
                this._grade = value;
            }
        }

        //primary key
        public int id
        {
            get
            {
                return this._id;
            }
            set
            {
                this._id = value;
            }
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        using (DataClassesDataContext c = new DataClassesDataContext())
        {
            var results = c.ExecuteQuery(typeof(GradeClass), "select student.id, grade from student inner join grade on student.id = grade.studentid");
            foreach (GradeClass g in results)
            {
                gradesLB.Items.Add(g.grade.ToString());
            }
        }
    }
}

Using AsParallel for parallel processing

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            BigInteger[] factorialArray = new BigInteger[100000];
            for (int i = 0; i < 100000; i++)
                factorialArray[i] = i + 1;
            var y = factorialArray.AsParallel().Aggregate((factorial, i) => factorial * i);


            //632382 ^ 518061
            //make sure to run on a quad-core computer or else it will take very long
            BigInteger[] exponent = new BigInteger[518061];
            for (int i = 0; i < 518061; i++)
                exponent[i] = 632382;
            var g = exponent.AsParallel().Aggregate((product, i) => product * i);
        }
    }
}

Finding duplicates using Linq

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = new int[] { 3, 3, 3, 4, 5, 6, 6, 7, 9,9,9,9,9 };

            var p = from n in arr 
                    group n by n into g where g.Count() > 1
                    select new {num = g.Key, count = g.Count()};
            foreach (var y in p)
            {
                Console.WriteLine(y.num + " " + y.count);
            }
        }
    }
}

Finding common elements using Linq

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr1 = { 5, 20, 3, 5, 6, 89, 9, 2, 1 };
            int[] arr2 = { 23, 34, 65, 65, 67, 2, 9 };
            List&lt;int&gt; list1 = new List&lt;int&gt;(arr1);
            List&lt;int&gt; list2 = new List&lt;int&gt;(arr2);
            IEnumerable&lt;int&gt; intersect = list1.Intersect&lt;int&gt;(list2);
            foreach (int i in intersect)
            {
                Console.WriteLine(i);
            }
        }
    }
}