Weblog Of Nirandas | home

Developer From INDIA

Sending email using a gmail account in C#

clock November 17, 2009 00:35 by author Nirandas

Sending emails using your gmail account is very simple in C#/VB.NET using .NET framework 2.0+. The below code snippet shows how.
More...

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Sorting list the easy way using lambda expressions

clock November 23, 2008 06:41 by author
Introduction of lambda expressions in .NET 3.5 have simplified many operations. One of them is sorting List<t> of complex types. For example assume that we have a type named Person and it has a Name property among other properties. Now if we want to sort a list of List<Person> on the Name property, we just have to use a single line of code.list.Sort((p1,p2)=>p1.Name.CompareTo(p2.Name));Or to sort on the Age propertylist.Sort((p1,p2)=>p1.Age.CompareTo(p2.Age));Here we are creating a delegate of Comparison<Person> using lambda expression and passing it to one of the overload of sort () method which accepts a Comparison<t>. The following code is breakdown of the above one liner into 2 lines.Comparison<Person> pc=(p1,p2)=>p1.Name.CompareTo(p2.Name);                                            list.Sort(pc);In short, we can use lambda expression to create delegates inline and pass them where ever a delegate can be passed. The List<t> class itself has many methods where you can pass delegates to perform certain actions. For example List<t>.ForEach() method.list.ForEach(o => Console.WriteLine(o.Name));Here we are outputting the names of persons in the list to the console without using a foreach loop.
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Create datetime range with custom interval

clock August 23, 2008 12:48 by author

In this post I will show a method using which we can create datetime ranges. This method is not specific to the datetime, instead it can be used with any type including int, long etc. There is a new method in .net framework 3.5 using which we can easyly create integer ranges. For example.

foreach(int i in Enumerable.Range(1,10))Console.Write(i);

However, in this post I will show how we can create integer ranges and datetime ranges with custom intervals etc.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Who Am I?

I am Nirandas - a developer from INDIA

Sign in