"WELCOME TO WINDOWS MOBILE DEVELOPMENT"
Post lepas dh talk sal azam hijrah baru aku..kali nie nk talk psal perkembangan terbaru aku, pe y current project n current progress..
Pd programmer2 newbies cm aku y kat luar sane, mksure korag cube wat WinMo platform programming, xkre la gine native C++ or managed code C#. At first mmg ssh, sbb byk sample code kat luar sane y ssh nk faham n berbelit2. Tp percya or x, pas try wat mesti korag tw cmane nk manipulate n utilize C# language ke tahap beyond from other people. Kenape? ha nie y nk cite nie..Usually, ms mula2 aku embark dlm C# nie, byk blaja dri video tutorial n source code kat tenet. Mostly, aku just pick part2 y aku nk gune or fhm je. Coz y laen byk xfhm. So skg, pd org y bace post nie aku nk show C# smart way n extreme programming.
Write code y sgt panjang dlm 1000 lines adalah cra y xbrape smart pd aku. First, bile ade bug, susah nk cri n trace. 2nd, susah nk manage. So, one of my way is to separate it with different but specific classes base on functionality and active time. Aku xnk cite byk sal mende nie coz nie bnde basic n bleh tanya Uncle Googlerudin. One thing y aku nk share adalah cara cmane nk communicate between classes y kite dh buat. Usually, kite akn gune array of string or data table bile nk pass data dlm collection y byk. Tp tahukah anda, array memerlukan kite untuk declare size nye skali, let say string[] a = new string[100]..
At that time, system dh create 100 memory space but unfortunately most of the time kite xgune pon sumer 100 tue..Suggestion aku, the smartest way is to use LIST instead of array bese. Seperti mane y kite taw, list xperlu nk declare size, ape y die taw just add(), remove(),removeat() and so on. Thats mean, put next object on top of other object (cam stack arr). Cara len, pe kate gune enumerable object, Bnde ni function cam list gak, tp lagi dynamic.
"Sample Code"
1. How to use List
public List
{
string query = "select whatData from tableName";
SqlCeConnection conn = new SqlCeConnection(connectionPath); //connection string anda
conn.Open(); //SqlCe adalah DB connection untuk WinMo
SqlCeCommand cmd = new SqlCeCommand(query, conn);
SqlCeDataAdapter da = new SqlCeDataAdapter(query, conn);
DataTable dt = new DataTable();
da.Fill(dt);
conn.Close();
List
for(int i = 0; i < dt.Rows.Count; i++)
{
yourList.Add(dt.Rows[i][0].ToString());
}
return yourList;
Explainantion - Ape y code kat atas wat adalah fetch data from aku punye Sql Server Compact database (thats why gune SqlCe, instead of Sql shj) n fill in all raw data dlm datatable. Then sumer raw data tue aku add dlm 1 LIST one by one. So the advantage is, LIST doesn't need any size to be declared at the first hand, n pastinye, jimat memory consumption as well as avoid software dri lack
2. How to use Enumerable Object
public IEnumerable
{
RegionInfo country = new RegionInfo(new CultureInfo("en-US", false).LCID);
List
foreach (CultureInfo cul in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
country = new RegionInfo(new CultureInfo(cul.Name, false).LCID);
countryNames.Add(country.DisplayName.ToString());
}
IEnumerable
return nameAdded;
}
Explaination - Penah x tgk page registration, Yahoo email ker, die mintak korag masukkan country name based on combobox y die bagi. Mane dapat snarai name negara 1 dunia tue?? 200 lebih beb, xkan programmer key in satu2. So, mission code kat atas nie adalah fetch all country name dri dlm system Windows.RegionInfo and add all raw data tue dlm ENUMERABLE object n walla! Korang dh ade snarai 200++ name negara ready to be use.
Ape kelebihan gune 2 menatang nie adelah y cm aku ckp td, bleh avoid software dri lack coz ia jimatkan memory space. Ape y aku minat skali kat bnde nie adalah bile object dh di add dlm List or Enumerable, kite bleh sort die, distinct kn die, mcm2 lagi to maksure data tue btul2 ready untuk di display kn kat mane2 UI element.
nice2..
ReplyDeletebila ar ak nak try nih...???
haha..
gud job bro..
thanks..haha
ReplyDeleteoooo....pehe doh!..
ReplyDeleteamik system nye kn zid...smart!
leh jimat ms..x perlu nk key in 1 by 1 dlm db..hehe..