In my previous blog post I have shared an easy tool to convert vb.net project. I have done a successful conversion of my projects data Layer from vb.net to c#, turned out it was awesome and less painful. So far every thing seems okay.
Then I found a small anomaly. In project reference I can see that “Microsoft.VisualBasic” library is referenced. That doesn’t sound right. And I deleted the reference and recompile the project. Some of the class thrown some compile error, and I had to fix them manually.
And today, I want to share those learning with the community. If you “Google” c# to vb.net cheat sheet you would get some very good cheat sheets.
VB.net Information.IsDBNull
There is my first lesson: When I deleted the “Microsoft.VisualBasic” I found out this little piece of code Information.IsDBNull:
protected static object SafeDisplayValue(object Value)
{
if (Information.IsDBNull(Value))
{
return null;
}
else
{
return Value;
}
}
So what's the equivalent c# code? bellow.
protected static object SafeDisplayValue(object Value)
{
if (Convert.IsDBNull(Value))
{
return null;
}
else
{
return Value;
}
}
Pretty interesting right, why IsDBNull check got into System.Convert namespace. Any way a good lesson learned.
Constants.vbNewLine
Any guess? yes that’s right “Environment.NewLine”
DateAndTime.Today
Yes that’s right DateAndTime.Today = DateTime.Now
I have more to share will share in next post.
No comments:
Post a Comment