Skip to main content

Posts

Showing posts from August, 2009

How to use list.Sum<> in System.Collections.Generic

List.Sum<> This will return the summation of named attribute. List<Item> listItem = new List<Item>();   Item T1 = new Item() { Name = "A" , Amount = 100 }; Item T2 = new Item() { Name = "B" , Amount = 600 }; Item T3 = new Item() { Name = "C" , Amount = 100 }; Item T4 = new Item() { Name = "D" , Amount = 150 }; Item T5 = new Item() { Name = "E" , Amount = 200 };   listItem.Add(T1); listItem.Add(T2); listItem.Add(T3); listItem.Add(T4); listItem.Add(T5);   Decimal D = listItem.Sum(P=>P.Amount); // sum of Amount Conditional Sum Assume that you want to get the summation of Amount lager than 100 Decimal D = listItem.Where(P=>P.Amount>100).Sum(P=>P.Amount); List.Sum() This will return the summation of the list. List< int > intList = new List< int >();   intList.Add(2); intList.Add(3); intList.Add(4);   int sum = intList.Sum(); // sum of Amount

How to use list.find<> and list.findall<> in System.Collections.Generic

List.find<> This will return first matched item from the list. List. FindAll<> This will return all matching items from the list. Item Class Code class Item { public int Amount; public string Name; } List<Item> listItem = new List<Item>();   Item T1 = new Item() { Name = "A" , Amount = 100 }; Item T2 = new Item() { Name = "B" , Amount = 600 }; Item T3 = new Item() { Name = "C" , Amount = 100 }; Item T4 = new Item() { Name = "D" , Amount = 150 }; Item T5 = new Item() { Name = "E" , Amount = 200 };   listItem.Add(T1); listItem.Add(T2); listItem.Add(T3); listItem.Add(T4); listItem.Add(T5); Method 1 Item Result= listItem.Find(P=>P.Name== "A" ); // item having "A" as it's item name   Item Result= listItem.Find(P=>(P.Name== "A" & P.Amount==100)); // item having "A" as it's item name and Amount as 100   Item Result= listItem.FindAll(P=>P.Amoun

Open Form (Push Form) in side a timer task in Blackberry

I tried several times to figure out how to push a form to a sreen inside a timer task. but meantime it gave me errors. but ultimately i found a way to do it. The solusion is invokelater(). To run a UI we have to run our code in event-dispatching thred.    class RemindTask1 extends TimerTask   {       public void run()        { Runnable NextScreen = new Runnable() {    public void run()          {           UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen()); UiApplication.getUiApplication().pushScreen(new frmComplite());    }    };             UiApplication.getUiApplication().invokeLater(NextScreen);      } }

Convert FAT32 to NTFS with out formating your harddisk

this is a simple nice command available in DOS commands. I had use this method in several occations with out any worries.  You can convert your FAT32 hard disk to NTFS with out formating or with out damaging your data. goto Run ---->type cmd (or any how get theh commant prompt) type convert c: /FS:NTFS (this will convert your C: drive to NTFS)

Public Key Cryptography in Windows Mobile Using RSA

Here shows how you can do public key cryptography encryption and decryption in windows mobile 6.0. In here stored the encrypted message and decrypt it using    private key. public partial class frmRSA : Form {           byte [] encMsg;         RSAParameters publickey;         RSAParameters privatekey;      private void menuKeyGen_Click( object sender, EventArgs e)    {        // 384 bits to 16384 bits in increments of 8 bits      // Create Public & Private Key and store..      RSACryptoServiceProvider RSAC = new RSACryptoServiceProvider (392);      publickey = RSAC.ExportParameters( false );      privatekey = RSAC.ExportParameters( true );       }      private void menuItem_Enc_Click( object sender, EventArgs e)    {         RSACryptoServiceProvider rs = new RSACryptoServiceProvider ();         rs.ImportParameters(publickey);         encMsg = rs.Encrypt( Encoding .ASCII.GetBytes(txttoEnc.Text), false );         txtEnc.Text

out Parameter in C#

out parameter is a very good option when need somthing give back from a method rather than return .  using out keyword we can access the given out parameter value.

How to Use delegate in side c#.net

Simple we can say delegate is a variable which holds methods instead of members. We are writing an application which will display either “Good Morning” or “Good Night” according to value entered.   (0-12:- “Good Morning” otherwise “Good night”) delegate string ReturnString (); // Declare this in top

How to Write a your own EventHander to a Class

This is example shows how you can write an own event to your class. I tried several methods and ways to do this even though this includes some basic logic behind. We are going to write Car class which raise, invoke or fire an event when 2 drivers are getting in to the car.   Following shows our interface to add drivers to the car. The following code describes how to handle the event. Code shows how to display message when two drivers are added to the car.