Go go to BarCamp Bangkok !!

Don't be rushed. BarcampBangkok is now over. But at least ,I went to that show and y'know. How could I say ... Fantastic!

That was my first time to participate and I grapped some cool technology to show you.

Before we begin this story I hope that you know what Barcamp is Right??

Everybody can participate. Everybody can vote and join the session or presentation that he wants.

So, I joined many classes and some were really impressive!

  • Avatar System : this japanese group presented their project that's about Avatar System ,enable you to use your Avatar in many platforms ,for example ,you can play a new game you've purchased with the characters in your other favourite games.
  • Discussion : discuss about how to open your software business in Thailand. Most of this classmates are foreigners and that made me really wondering why Thai people just omitted this class and let others discussed how to build software business in Thailand. I've talked with one open-mind guy that he said he could help Thai developers to make his dream became true! and he's running the financial consultant business for Thai software developers. At the end of the discussion ,the conclusion came with the idea of how to build the software business in Thailand ,they said that in Thailand there was a wide gap between the software prototype and real produced software ,that means Thai developers should have some kinds of "association" that can help about the financial issues. For me ,I hope that one day the govt will care about this too!!!
  • Poken :  Do you want to poken? what do the poken things really mean. Okay.. it likes your contact lists. Imagine that you enter in a bar and then you meet some guys that you want to make friends with. First thing you need to do is - ask them for the email or mobile phone no. or Twitter ID ,etc. right? So now you're noting all that things ,some give email some phone no. some Twiiter. Ahh! sh*t how could I manage all these things. At that time if you have "Poken" ,all you need to do is just "poken them"! (like in the pictures below) sound nice huhh? Moreover, they provide the website that help you easily manage you contact lists. In each contact ,it contains your friend's information ;picture,TwitterID,email,etc. You don't have to be shame anymore just move your Poken near your friend's Poken you then grab his contact card that all ! You can read more about this Poken thing.
      : The way you poken each other!


 

  •   Augmented Reality : some of you might not know what is AR thing. Some that know can skip (nothing new for you :P). I had a chance to see some movement of Thai software developers that tapped into this field and they've made the softwares mainly for educational purpose and I think that it suits well with AR. Student can understand the lesson more effective with Augmented Reality. You may wonder how AR works. For simplicity, it'll analyse an image coming from webcam and find out where is the corner of that image and the program will display a model/animation that matched with the distinct image. They also maintain the position of that model/animation accordingly with the movement of recorded image.


    I only know that nowadays you can make Augmented Reality program via ARToolkit or others toolkit .I've heard that there're some libraries available in Java ,C++ platfoms and ActionScript (i'm not sure about actionscript if you have any information please leave us a comment.. we'll appreciate)
  • Many many more topics I cannot put them all to show you. I'd like to invite you to join Barcamp next times if you have a chance. Barcamp'll be held in other countries around the world as well join yours!   :D

 

Categories:   News
Actions:   E-mail | del.icio.us | Permalink | Comments (5) | RSS


มาติด Speed ให้หมาไฟกัน : 10 handy Firefox "about:config" hacks

ขอประเดิมเป็นเรื่องแรกเลยละกัน คิดว่าหลายๆคน คงจะรู้จักหมาไฟ(FireFox)กันมาบ้าง แต่สังเกตบางกันไหมว่า ยิ่งออกมารุ่นใหม่ๆ อย่าง 3.0.1 ความเร็วหรือความเสถียร มันก็ค่อยๆกร่อนลง (Hank บ่อยบ้าง..เปิดช้าบ้าง....) วันนี้ โฮมไดเรกด์ขอเสนอ...เฮ้ย... วันนี้ก็เลยจะเอาวิธีการปรับแต่ง น้องหมาไฟ ให้เร็วขึ้น ดีขึ้น(บ้าง)  มาฝากคับ

หมายเหตุ!!!

about:config เป็นการแก้ขั้นสูงของ Firefox ซึ่งอาจเกิดความเสียหายได้ หากแก้ค่าผิดพลาด เพราะฉะนั้น ทางเราไม่รับประกันต่อความเสียหายที่อาจเกิดขึ้นได้ (อย่างมากก็ลงใหม่มั้ง?!) ทางเราขอแนะนำให้ทำการ Back Up ค่า prefs.js ก่อนทำการ HACK นะคับ แต่หากว่า ไม่สามารถเข้าไปแก้ไขได้ ให้ลองเข้า แบบ Safe Mode โดยใช้ Command : firefox -safe-mode แล้วเลือก Reset All User Preferences To Firefox Defaults เพื่อเรียกมันกลับมาในค่า Default ทั้งหมดคับ (เอากระดูกมาล่อแทนได้ปะ = =)

ถ้าพร้อมแล้ว... ใส่หมวก..เปิดไฟ...เฮ้ย... ไปกันเลยคับ

1) Speed up Firefox

ขั้นแรก ลอง Search "Pipelining" ใน the filter

network.http.pipelining: Change this to true.

network.http.proxy.pipelining: Change this to true.

network.http.pipelining.maxrequests: Change this to 8.

ต่อมาก็ search คำว่า "max-connections" :

network.http.max-connections: Change this to 96.

network.http.max-connections-per-server: Change this to 32.

 

2) Disable antivirus scanning

Tip นี้สำหรับ Window เท่านั้นคับ... ลองคิดเล่นๆนะ ถ้าเราจะโหลดไฟล์ขนาดใหญ่ๆ แล้วเจ้า AntiVirus ของเราก็ต้องมา Scan ไปเรื่อยๆ มันก็หน่วงเครื่องใช่ไหมหละ? เพราะฉะนั้น ปิดมันซะเลย...(แต่ถ้าไม่โหลดก็กลับมาเปิดก็ดีนะ... ไวรัสเข้าอย่าหาว่าไม่เตือน = =)

search คำว่า  "scanWhenDone" :

browser.download.manager.scanWhenDone: Change this to false.

3) Open Javascript popups as tabs

สำหรับคนที่รำคาญ PopUp ไม่ว่าจะมาจาก Java Script  หรือ อะไรก็ตาม บางทีมันน่ารำคาญนะ..เช่น จะเข้าเว็บนึงแล้วมี PopUp โฆษณามาบัง ไม่ก็เปิดเป็น PopUp แล้วก็ปิดไป(Virusแหงมๆ) เราก็จับมาเป้น new Tab แทน แล้วก็ ปิดอย่างง่ายดาย อิอิ

search คำว่า  "newwindow" :

browser.link.open_newwindow.restriction: Change this to 0.

4) Spell checking in all fields

ค่า Default ของ FF จะเช็คตัวสะกดของเราใน Text Field เท่านั้น (multiple-line text boxes) ที่นี้ ถ้าเราอยากให้มันตรวจทุก Text Box หละ ไม่ว่า multiple-line หรือ single-line ก็จัดให้..

search คำว่า  "spellcheckdefault" :

layout.spellcheckDefault: Change this to 2.

5) Open search bar results in new tab

ทางด้านขวามือ คือ Search Bar ทุกครั้งที่เราเรียกใช้มัน มันจะแสดงผลใน Tab ที่เปิด ณ ขนะนั้น.. ถ้าเราไม่ชอบ อยากให้มันเปิดเป้น Tab ใหม่ซะ เผื่อ เปิดงานไว้ แล้วดันไปใช้ Search box ก็เปิดหน้าซ้ำอีก.. เราก็จัดให้...

search คำว่า  "openintab" :

browser.search.openintab: Change this to true.

6) Auto export bookmarks

ใน Firefox 3 ค่า Default จะตั้งให้ Auto Export Bookmarks อยู่แล้ว (มีใครไม่รู้มั่ง...ผมคนนึงแหละที่เพ่งรู้ = =) แต่ที่เป็นปัญหา นิดๆ คือ.... มัน Export เป็น places.sqlite แทนที่มันจะเป็น bookmarks.html ซะนี่สิ... จะเอาไปใช้กะ Browser ตัวอื่นก็ไม่ได้ >_<" แต่เราก็แก้คับ..

search คำว่า  "autoExportHTML" :

browser.bookmarks.autoExportHTML: Change this to true.

7) Disable extension install delay

เคยลองลง Extension บ้างกันยังเอ่ย... เวลาที่จะ Install ทีนึง ก็มี PopUp Delay ก่อน install ... แรกๆก็ไม่ได้คิดอะไรนะ..แต่พอลงหลายๆตัว นั่งรอหลายๆครั้ง รำคาญ อะ ปิดมันซะ

search คำว่า  "enable_delay" :

security.dialog_enable_delay: Change this to 0.

8) View source code in an external editor

สำหรับ นักพัฒนา หรือ User ที่ขอบซุกซน (แบบผมไง อิอิ) ชอบนั่งอ่าน Code เว็บอื่น เผื่อเจออะไรแปลกๆ หรือ อยาก Copy ในรูปของ Tab HTML แต่เวลาที่ Firefox จะเปิด source code จะใช้ Firefox เปิดเอง.. ซึ่ง บางคนก็รักใน Editer ส่วนตัวอยู่แล้ว..อย่าง EditPlus หรือ อะไรก้ตาม... Firefox ก็พร้อมจัดให้คับ

search คำว่า  "view_source.editor" :

view_source.editor.external: Change this to true.

9) Get more add-on search results

ใครชอบหา Add-on ใน Search ของ Firefox บ้าง ( Tools->Add-on )... เงียบแฮะ 555 อืม ถ้าได้เคยลองใช้นะ เวลา Search 1 ครั้ง มันจะขึ้น Result ให้แค่ 5 Add-ons เท่านั้นอะ.. แต่ถ้าไม่จุใจพอ เน็ตแรงแล้ว จะเสียเวลาทำไมหละ.. ลองนี่เลย..

search คำว่า  "getAddons" :

extension.getAddons.maxResults: Change this to 10 (หรือมากกว่านั้น :P).

10) Redefine the Backspace button

ปกติ ไม่ว่าใน Firefox หรือ IE หรือ Browser ตัวอื่น BackSpace จะเป้นการ Back กลับไป Page เก่าใช่ปะ? แต่ถ้าอยากแกล้งคนหละ.. หรือไม่ชอบ ไม่ถนัดอะ อยากให้เป้น Forward อะ FF ทำได้ครับ..

search คำว่า  "backspace" :

browser.backspace_action: Change this to 0 for previous page and 1 for page up.

 

Credit : http://blogs.techrepublic.com.com/10things/?p=719    &&   http://www.ictv5.co.cc/forum/index.php?topic=239.0

อ่า..... วันนี้ก็ ขอพอแค่นี้หละคับ... ไว้คราบหน้าจะเอา Tip แปลกๆมาฝากอีก... สวัสดี

Categories:   News | Tip(s)
Actions:   E-mail | del.icio.us | Permalink | Comments (9) | RSS


Introduction to C# part 1 : namespace

วันนี้เราจะเริ่มทำการเขียน C# กันละนะคับ โดยเริ่มตั้งแต่พื้นฐานเรื่อง namespace
ผมจะเทียบการเขียน C# กับการเขียน JAVA เป็นหลักนะคับ เพื่อที่จะได้เข้าใจกันได้ง่ายขึ้น

namespace เปรียบได้กับ package ใน JAVA คับ ซึ่งจะเป็นเหมือนตู้ที่เก็บคลาสอยู่นั่นเอง

1.สร้าง project ที่เป็น Console Application ขั้นมา

2.สร้างไฟล์แรกชื่อ file1.cs

using System;
namespace First
{
    public class A
    {
       public A()
       {
           Console.WriteLine("Namespace:First.Class:A");
       }
    }
    public class B
    {
       public B()
       {
           Console.WriteLine("Namespace:First.Class:B");
       }
    }
}

3.สร้างไฟล์ที่สองชื่อ file2.cs

using System;
namespace Second
{
    public class A
    {
        public A()
        {
            Console.WriteLine("Namespace:Second.Class:A");
        }
    }
    public class C
    {
        public C()
        {
            Console.WriteLine("Namespace:Second.Class:C");
        }
    }
}

คราวนี้เรามาดูในไฟล์หลักที่มี main อยู่กันครับ

using System;
using First;
using Second;

namespace NamespaceTester
{
    class Program
    {
        static void Main(string[] args)
        {
            C c = new C();
            /*
             * A a = new A(); // ถ้าไม่คอมเมนส่วนนี้จะ error คับ
             * เนื่องจากคลาส A มีอยู่ทั้งใน namespace First, Second ทั้งคู่
             * เราจึงต้องระบุ  namespaceให้จัดเจนคับจึงจะไม่มีปัญหา
            */
            First.A aA = new First.A();
            Second.A aB = new Second.A();
            //Console.ReadLine(); /*ถ้ารันแล้วเรายังไม่ทันเหนผลแล้วจอดับไปให้ลบcommentหน้าบรรทัดนี้ออกนะคับ*/
        }
    }
}

เห็นหรือยังคับกับวิธีการใช้ namespaceอย่างง่ายๆ
ส่วนใครที่งงกับ Console.WriteLine() ไม่ต้องตกใจไปคับ มันเหมือนกับการ print ออกมาอย่าง System.out.println() คับ

การใช้namespaceก็จบลงเท่านี้ละนะค้าบ แล้วคราวหน้าเรามาต่อกันกับ Data types กันนะคร๊าบ ^^

Categories:  
Actions:   E-mail | del.icio.us | Permalink | Comments (13) | RSS


Jet Pack Add-on for Firefox

สวัสดีครับ วันนี้ผมก็ไปเจอกับ JetPack ของ Mozilla Labs เข้าพอดีครับ ซึ่งก็น่าสนใจมากๆทีเดียว เลยคิดว่าจะเอามาฝากครับ JetPack คร่าวๆก็คือ Plugin เสริมของ Firefox ซึ่งจะช่วยให้การสร้างและ install add-on ใน Firefox ดีขึ้นอย่างมากครับ เพื่อนๆสามารถ install pluginนี้ ได้จาก https://addons.mozilla.org/en-US/firefox/downloads/latest/12025/addon-12025-latest.xpi เลยครับ  ที่ผมเห็นว่าJetPackเด็ดดวงก็คือ

  • ประการแรก JetPack ทำให้คุณสร้าง Addon ได้โดยใช้เพิ่งแค่ Javascript CSS HTML แค่นี้เอง ไม่ต้องลำบากเขียนอะไรให้วุ่นวายเหมือนกับ addons ธรรมดาของ Firefox
  • ประการที่สอง JetPack ทำให้การ install addons ใหม่ลงใน Firefox ไม่ต้อง restart firefox หลัง install ทำให้สะดวกขึ้นมากเลยครับ คือ install แล้วใช้ได้ในทันที
  • ประการที่สาม JetPack ทำให้คุณเขียน code น้อยลง อย่างตัวอย่าง application ก็เช่น Email Notifier - Status Bar Demo (ต้่องลง JetPack api ที่linkด้านบนก่อน) ด้วยการเขียน code เพียง 50 กว่าบรรทัด!!!
  • สามารถใช้ร่วมกับ capabilities ใหม่ของ Mozilla ได้อย่างเช่นตัว <audio> <video> <canvas> ครับ (ถ้าใครลง Firefox ตัวใหม่ๆจะเห็นว่า มีการเพิ่ม capabilities เหล่านี้ลงไป)
  • Lightweight แต่ Powerful ครับ
  • สามารถใช้ร่วมกับ third party language อย่างเช่น jQuery Dojo และ API จากwebsite ต่างๆได้ครับ เช่น Twitter Google Map etc.

หลังจากอ่านคร่าวๆแล้วรู้สึกว่า "มันเป็นอนาคตของ plugin จริงๆ" ครับ เพราะ คุณและคนอย่างผม สามารถพัฒนา addons ได้ง่ายๆ เลยครับ เอาไปติดตามเว็บของเราก็ได้ครับ ไม่แน่ผมอาจจะทำมาติด blog นี้ก็เป็นได้ ฮะฮ่าาา ใครที่ลองเล่นก็ leave comment มาบอกให้theblogfor รับรู้แล้วแบ่งมาใช้ บ้างนะครับ

แล้วนอกจากนี้ developer ยังสามารถ ใช้ Bespin ในการพัฒนา หรือ อาจจะพิมพ์ addressbar ว่า about:jetpack >เลือก develope ก็ได้ครับ ในนั้นก็จะมี JetPack Library ไว้พร้อม

Image Swapper Demo

 

 

Categories:   News
Actions:   E-mail | del.icio.us | Permalink | Comments (14) | RSS


Hello LINQ (in C#) part 1

สวัสดีอีกครั้งครับ วันนี้ก็เป็นหัวข้อที่น่าสนใจทีเดียวมาเริ่มกันเลย..

คอร์สนี้สำหรับผู้ที่เขียน .NET ไม่ว่าจะ VB หรือ C# และเคยทำงานร่วมกับ SQL XML Textfile มาครับ ประกอบไปด้วย

  • เข้าใจ LINQ
  • ปูพื้นฐานก่อนใช้ LINQ
  • LINQ as language extension
  • Query Operators
  • Query Expressions
  • LINQ to SQL
  • LINQ to Textfile
  • LINQ to XML
  • Future of LINQ (maybe)

ก็คงมีกันหลาย part นะครับ ไม่เป็นไรครับ เพื่อความรู้ Laughing

LINQ(Language Integrated Query) นั้นคืออะไร สำคัญฉไน เหตุใดใยฉันจึงควรรู้ คำตอบคือ สำคัญครับ สำหรับ Developer ที่ต้องการให้สรรพสิ่งง่ายดายและรวดเร็วขึ้น ง่านต่อการ maintain code อีกทั้งยังมี performance ที่น่าพึงพอใจอีกด้วย (ทั้งนี้ส่วนใหญ่มันขึ้นอยู่กับคนเขียนด้วย ไม่ได้ LINQ อย่างเดียว) รับรองเลยครับว่า ชีวิตท่านจะสะดวกสบายขึ้นจริงๆ เราจะแบ่งอธิบายเป็นข้อๆเพื่อความเข้าใจง่าย

LINQ คือ?

- คือ language extension(ตัวต่อยอดของภาษา) อย่างหนึ่งช่วยทำให้ การเขียนโปรแกรม C# หรือ VB ง่ายดายยิ่งขึ้น

- คือ toolset ที่ทำให้การทำงานกับ data ต่างๆ สะดวกมากๆยิ่งขึ้น จำแนกออกเป็นหลายประเภท เช่น LINQ to SQL , LINQ to XML ,LINQ to Textfile ไว้ค่อยว่ากัน

ภาพนี้จะช่วยให้เข้าใจง่ายขึ้น(หรือยากขึ้น)

 

ใน Visual Studio 2008 นั้นมีการใช้ LINQ อย่างแพร่หลาย(หรือหลายคนจะใช้โดยไม่รู้ตัว) สังเกตุจากทุกครั้งจะมีการ include System.Linq โดยอัตโนมัติเวลาสร้างหน้าcode ใหม่

LINQ ทำไม?

- คุณเคยไหมเวลาเขียน code แล้วรู้สึกว่า ทำไมต้องการนั่งเขียนอะไรแบบเดิมๆ ซํ้าๆ วนลูปแบบเดิมๆแต่แค่เปลี่ยนชื่อ code ที่ยาวยืด(plumbing code) ต้องมา iterate ลูปกันจนเบื่อ ทั้งหมดนี้ LINQ ช่วยท่านได้

- คุณรู้สึกไหมว่าการเชื่อมต่อกับdatabaseทำไมado.net ถึงได้วุ่นวายนักต้องเขียนระบุ connection command ต้องรู้จักภาษา sql ละเอียด ต้อง map relational data เข้ากับ object ใน code เราอีก

- ต้องศึกษาภาษาเฉพาะทางสำหรับ xml ซึ้งมีมากมาย อาทิ XPath XQuery NHerbinate(ตัว mapping .NET code กับ XML) หรืออะไรก็ตาม ทำไมหละๆ ไม่ทำให้มันสักหนึ่งอันไปเลย

- ถ้าวันนี้ฉันอยากจะรับdata จาก xml แล้วเอามาเก็บ in memory แล้วเอาไปบันทึกลง sql server database หละ จะต้องเขียนcode กันสักแค่ไหน ช่องว่างตรงนี้แหละคับที่เรียกว่า "impedance mismatch" (อย่าตกใจ ไม่มีอะไรเกี่ยวกับimpedanceในphysics)

- และปัญหาอื่นๆที่ผมนึกไม่ออก

ปัญหาทั้งหมดนี้ LINQ can help you!

ปูพื้นฐานก่อน LINQ

ยังไงๆซะ คุณควรจะมีความรู้ภาษาระดับ advance .net มาก่อนที่จะเข้าใจ LINQ ได้ครับ ไม่งั้นคุณจะเป็นแค่ ผู้ใช้ ไม่ได้ ผู้ที่เข้าใจจริงๆครับ สำหรับสิ่งเหล่านี้ก็เป็นพื่นฐานที่ผมจะ refresh ให้คุณ

  • Implicit typed local variables : ง่ายๆ เช่น var i = 5; ตัวนี้เรียก Implicit typed local variables แทนที่จะ int i =5; เพราะ compiler จะอ้างอิงว่าtypeของvarจาก expression ของมันซึ่งคือ 5 ทั้งนี้รวมไปถึงตัวแปรชนินอื่นๆอาทิ var s = "Hello"; var numbers = new[] {1,2,3,4}; var dicts = new Dictionary<int,MyData>(); เป็นต้นลองเอาไปทดลองใช้กับ code ดูครับ เช่น

var lines = new LinesFromDatabase();

foreach(var line in lines.GetOneLine()){

...

}

  • Object Initializers : สมมติมี

public class Student{

public string ID{get; set;}

public string Name{get; set;}

}

ปกติเราจะประกาศ Object สักอันก็ต้องทำแบบนี้ใช่มั้ยครับ

public class StudentSample{

Student stu1 = new Student();

stu1.ID = "50880xx";

stu1.Name = "Ochin TheGang";

}

แต่ Object Initializers คุณสามารถ

public class StudentSample{

Student stu1 = new Student(){ID="50880xx",Name="Ochin TheGang"};

}

ต่อไปเวลาเขียนExceptionก็สะดวกแล้ว แค่ throw new Exception("your message"){Source="exception source"};

เสริม : Collection Initializers คล้าย Object Initializers แหละครับ ไม่มีใช้ใน LINQ นะ สมมติเราอยากได้ List ของ Student

แบบเก่า

var stuList = new List<Student>();

stuList.Add(new Student{ID="123",Name="dd xx"});

stuList.Add(new Student{ID="567",Name="yy zz"});

แต่ Collection Initializers โดยความฉลาดของ compiler ทำให้ไม่ต้องเขียน Add ให้มากมาย

var stuList = new List<Student>(){new Student{ID="123",Name="dd xx"},new Student{ID="567",Name="yy zz"}}

  • Lambda Expressions : สำหรับตัวนี้ก็ต้องมีความเข้าใจใน Delegate ก่อนครับ เพราะ Lambda Expressions ง่ายๆก็คือการทำให้ Delegate สะดวกยิ่งขึ้นนั่นเอง

Delegates คือการ อ้างอิง pointer ไปที่ method ตัวอย่างง่ายๆคือเราไม่ได้อยากส่งแค่ value เข้าไปใน function แต่เราอยากส่ง function เข้าไปใน function เพื่อความเ้ข้าใจง่าย สมมติว่าเราอยากได้ customer ที่รวยโดยมีเงินpocket money มากกว่า 100000บาท

static string GetTotalMoneyInStringFormat(Func<Customer,Boolean> checkIfGreaterThan){

var richCustomerList = new List<Customer>();

foreach(var customer in GetCustomerListFromSomewhere()){

if(checkIfGreaterThan(customer))

richCustomerList.Add(customer);

}

}

เวลาเราเรียกใช้ function นี้ก็ string output = GetTotalMoneyInStringFormat(delegate(Customer customer){return customer.PocketMoney > 100000}); นี่แหละครับคือ delegate แบบ Anonymous method (คือเขียนmethodแบบ inline scripting) ส่วน delegate แบบธรรมดานั้นไม่ขอพูดถึงแล้วกันครับ เราไม่ได้ pass value เข้าไปแต่เรา pass ให้มันทั้ง function delegate จะมีประโยชน์มากถ้าเรารู้จักใช้ครับ แต่ถ้า overuse จะทำให้มีปัญหาเรื่อง performance ตามมาครับ สำหรับรายละเอียด มี Guru provides ไว้แล้วครับ Memory Leak with delegates and workflow foundation By Omar

สำหรับ Lambda Expressions จะทำให้code เรา concise ขึ้นมากครับ(การเขียนAnonymousข้อเสียคือความเป็นimperativeซึ่งทำให้อ่านยากและยืดยาว แต่lambdaนั้นเรียกว่าเป็นการเขียนแบบfunctional programmingเลยก็ว่าได้) จากตัวอย่างที่ผ่านมาเราสามารถเรียก string output = GetTotalMoneyInStringFormat(cus=>cus.PocketMoney >100000); จบครับ ได้คำตอบเท่ากัน

cus=>cus.PocketMoney >100000 อ่านไดว่า cus "ไปยัง" cus.PocketMoney >100000

lampda expression นั้นแบ่งเป็น 2 แบบ คือ statement lambda เช่น x=>{return x+1;} หรือ cus=>Console.WriteLine(cus.PocketMoney) เป็นต้น  กับ expression lambda เช่น x=>x+1 หรือ cus=>cus.PocketMoney เป็นต้น

จากตัวอย่างข้างบน Func< Customer,Boolean> checkIfGreaterThan คงจะสงสัยสิครับว่าคืออะไร Func<Customer,Boolean> คือ delegate type ครับ เราควรจะต้องรู้จัก delegate types เช่น

delegate void Action();

delegate void Action<T1,T2>(T1 args1,T2 args2);

delegate void Action<T1,T2,T3>(T1 args1,T2 args2,T3 args3);

delegate void Action<T1,T2,T3,T4>(T1 args1,T2 args2,T3 args3,T4 args4);

delegate TResult Func<TResult>();

delegate TResult Func<T1,TResult>(T1 args1);

delegate TResult Func<T1,T2,TResult>(T1 args1,T2 args2);

delegate TResult Func<T1,T2,T3,TResult>(T1 args1,T2 args2,T3 args3);

delegate TResult Func<T1,T2,T3,T4,TResult>(T1 args1,T2 args2,T3 args3,T4 args4);

จาก Func<Customer,Boolean> checkIfGreaterThan  ของเราเป็นแบบ delegate TResult Func<T1,TResult>(T1 args1); ครับ เข้าใจได้ว่า functionนี้return Boolean รับinputเป็นtype Customer มันจะแสดงความสัมพันธ์ให้เข้าใจอย่างง่ายๆเลยครับ

เพื่อความเข้าใจง่ายว่ามันเกี่ยวกับ lambda expressions ยังไงผมขอยกตัวอย่างความ compatibility เช่น

Func<int,int,double> calculate รับค่าของ (x,y)=>x*y/2; ได้

Action<string> printName รัยค่าของ s=>Console.WriteLine(s); ได้

เป็นต้น ครับ ที่อธิบายอย่างละเอียดเพราะจำเป็นต้องเข้าใจครับ อีกทั้งยังเป็นประโยชน์กับคุณเองในอนาคตด้วย

 

ยังเหลืออีก 2 อย่างที่ยังไม่ cover สำหรับการปูพื้นฐาน ยังไงก็อดใจรอนะครับ ในฉบับหน้า

  • Extension Methods
  • Anonymous Types and Methods

Categories:   .NET ASP.NET C#
Actions:   E-mail | del.icio.us | Permalink | Comments (7) | RSS


 

Tag Cloud