Welcome to Jacksonville Developers User Group Sign in | Join | Help

Just a waste of time

Over and over again I find developers creating "wrappers" for the Visual Basic runtime library. It is a waste of time. Especially when I see them just creating a method called "DateDiff" written in C#. Then this C# "DateDiff" calls the DateDiff method in the Microsoft.VisualBasic.DateAndTime module.

If you want to use the functionality in the VisualBasic library why not reference it directly? Why add another layer?

If the mere sight of the "V" and "B" in VisualBasic makes you want to blow chunks or press a red hot metal poker deep into your good eye then consider re-inventing the wheel.

//get the difference in number of days

DateTime firstDate = DateTime.Now;

DateTime secondDate = DateTime.Now.AddDays(-2);

TimeSpan resultingSpan = firstDate.Subtract(secondDate);

return resultingSpan.Days;

OR

//get the difference in number of months

DateTime firstDate = DateTime.Now;

DateTime secondDate = DateTime.Now.AddMonths(-24);

return firstDate.Month - secondDate.Month + ((firstDate.Year - secondDate.Year) * 12);

The possibilities continue on...

Published Friday, September 28, 2007 5:16 PM by tbates
Filed Under:

Comments

No Comments
Anonymous comments are disabled