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


Find matching items from a List - simple example of VB.NET 2008 lambda function

clock November 9, 2009 05:15 by author Nirandas

Here is a very simple example showing how to find all matching items from a generic List(of T) using lambda functions in VB.NET.

Dim MatchedItems As List(Of User) = Members.FindAll(Function(u As User) (u.Age<18))

Here the FindAll() function is accepting a Predicate(Of User) Delegate. And we can pass lambda functions where ever a delegate to a function is accepted. The FindAll() method calls our lambda function for each item in the list for deciding whether the item matches our requirements. If it does (our Predicate(Of T) returns True) the Item is included in the returned list.

Another nice thing is that this feature (lambda functions) are supported even in projects where the target .NET framework version is 2.0. So, we can use these lambda functions in our .NET 2.0 application as wel.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

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


Online vb.net to C# converter from telerik

clock October 4, 2009 04:17 by author Nirandas

Here is a online converter from telerik which can convert code between vb.net and c# and back to c# from vb.net. It does most of the tough work however it is not perfect. For example the following statement is perfectlly legal in vb.net
txt=num.ToString
When it is converted to C#, the result is invalid code
txt=num.ToString;

  1. Note that C# explicitly requires parentheses after method names even if the method doesn’t take any arguments. Surely the converter should have taken care of it.
  2. Another issue which I encountered while converting code from vb to c# is absents of optional arguments in c#. You would have to make adjustments if you use optional parameters a lot.
  3. Remember to explicitly add
    using System;
    and such commonly used namespaces. It look strange when classes in System namespace like Exception are not recognized.

Remember to verify that the converted code works as well as before — compiling is just not enough!

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

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


Redirecting the console output to a stream

clock September 4, 2009 09:16 by author Nirandas

Here is the code:

StreamWriter stream = new StreamWriter(“output.txt” );
stream.AutoFlush = true;
Console.SetOut(stream);

More...

Be the first to rate this post

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


Fastest way of copying bytes in C#

clock July 19, 2009 11:13 by author Nirandas

If you ever have come across having to copy a block of bytes from an array to another location, the fastest method I found in .NET framework is using the System.Buffer.BlockCopy() method. This will give better performance compared to other methods and can be used on other basic types as int etc.
More...

Be the first to rate this post

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


Expand short URLs of tinyurl, bit.ly, tr.im etc

clock June 29, 2009 05:47 by author Nirandas

Popularity of services like twitter and other social networking sites have resulted in an exponential growth in the number of URL shortening services. bit.ly, tr.im are just few of the example. Though these URL shortening services solve a major issue of long URLs and save space where it is required, these services have a major downside to it.
More...

Currently rated 5.0 by 2 people

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


Who Am I?

I am Nirandas - a developer from INDIA

Sign in