Search This Blog

Thursday, April 7, 2011

Take Last Operators

int[] grades = { 59, 82, 70, 56, 92, 98, 85 };

var topThreeGrades = grades
.OrderBy(grade => grade)
.TakeLast(3);

Console.WriteLine("The top three grades are:");
foreach (int grade in topThreeGrades)
{
Console.WriteLine(grade);
}
/*
This code produces the following output:

The top three grades are:
98
92
85
*/
----------------------------------------------------
string[] fruits =
{
"apple",
"passionfruit",
"banana",
"mango",
"orange",
"blueberry",
"grape",
"strawberry"
};

var query = fruits
.TakeLastWhile(fruit =>
string.Compare("orange",
fruit, true) != 0);

foreach (string fruit in query)
{
Console.WriteLine(fruit);
}

/*
This code produces the following output:

blueberry
grape
strawberry
*/
---------------------------------------

string[] fruits =
{
"apple",
"passionfruit",
"banana",
"mango",
"orange",
"blueberry",
"grape",
"strawberry"
};

var query = fruits
.TakeLastWhile((fruit, index) =>
fruit.Length >= index);

foreach (string fruit in query)
{
Console.WriteLine(fruit);
}

/*
This code produces the following output:

strawberry
*/

Join two lists using LINQ

static void Main(string[] args)
{
// Create an instance
MyEntitiesDataContext myEntitiesDataContext = new MyEntitiesDataContext("http://servername:2010/sites/test/");
// Get the lists from the site
EntityList aList = myEntitiesDataContext.GetList("A");
EntityList bList = myEntitiesDataContext.GetList("B");

List aListItems=(from a in aList select a).ToList();
List bListItems = (from b in bList select b).ToList();

IEnumerable mergedList = aListItems.Union(bListItems);

foreach (Item items in mergedList)
{
Console.WriteLine(items.Title.ToString());
}
}

Call javascript funcation sharepoint Grid View.

<asp:templatefield HeaderText="Approve">
HeaderStyle CssClass="ms-vh2" Font-Bold="True" />
<ItemStyle CssClass="ms-vb2" />
<ItemTemplate>
<asp:HyperLink ID="hplink" runat="server" NavigateUrl='<%# Eval("ID", "javascript:getEditPM({0})") %>'>Approve</asp:HyperLink>
</ItemTemplate>
</asp:templatefield>