Hari ni, saya berkesempatan untuk write simple code menggunakan new C# language dalam Orcas. Salah satu language features baru ialah Query Syntax
Query Syntax ialah cara mudah untuk filter any information dalam memory collection. Ianya menggunakan LINQ query operator. Contoh dibawah
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Linq;
using System.Data.Linq;
using System.Linq;
namespace ExtensionMethod
{
public class Program
{
public static void Main(string[] args)
{
List<People> pe = ListPeople();
IEnumerable<People> p = pe.Where(p1=>p1.Name.Equals("Azam"));
foreach (People pp in p)
{
Console.WriteLine(pp.Name);
}
Console.ReadLine();
}
public static List<People> ListPeople()
{
List<People> p = new List<People>
{
new People {Name="Azam",Address="Melaka"},
new People {Name="Kamal",Address="Wilayah"}
};
return p;
}
}
public class People
{
public string Name { set; get; }
public string Address { set; get; }
}
}
0 comments:
Post a Comment