Amazon Wish List News RSS feed. Development Blog Browse the Forums  
  Overview - Downloads - Examples - News Feed - Contact Info -

Tips for VB.NET Developers

I come from the vb world, but in the .NET context I develop the libraries and controls in C# and the other layers in VB.NET.

This library has near all the examples and snippets in C# in the future I plan to add the VB.NET examples... for now I want to write some tips to translate the code and use the library anyway.


Check these excellent VB.NET - C# comparison cheat sheets
You can use one of these excellent converters between C# <-> VB.Net
Developer Fusion (online)
KamalPatel.Net - Convert C# to VB .NET (online)
Convert NET - Useful translation utility (standalone)

Tips

  1. The using directive in C# is the Imports directive in VB.NET
     
  2. The typeof() keyword in C# is the GetType() keyword in VB.NET
     
  3. The principal difference between this two language is the use in the Attributes.
    In C# the attributes are enclosed between [] while in VB.NETyou need to use <>

    C# example:

             [ FixedLengthRecord
             public class OrdersFixed

    VB.NET example:

             < FixedLengthRecord > _ 
             Public Class OrdersFixed

    Remember: to use the _ (underscore) when you put the definition in the next line.
     
  4. Other difference is the type convertion instruction.

    In C# the cast is the destination type enclosed between ()

        Orders[] res = (Orders[]) engine.ReadFile(@"Test.txt");
        Orders[] res = engine.ReadFile(@"Test.txt") as Orders[];

    In VB.NET we can use DirectCast or CType to do the same thing.

        Dim res As Orders() = CType(engine.ReadFile("Test.txt"), Orders())

        Dim res As Orders() = DirectCast(engine.ReadFile("Test.txt"), Orders())

    Note: DirectCast has the less performant hit, but CType is more clear.

  5. The last difference is about generics

    In C# the generics class are defined:

        FileHelperEngine<Orders> engine = new FileHelperEngine<Orders>();

    In VB.NET In this other way:

        Dim engine As New FileHelperEngine(Of Orders)()

See also

Must Read - Quick Start Guide - Attributes List - F.A.Q. - Examples of Use - Contacts & Credits - Donations

© 2005-07 to Marcos Meli

FileHelpers on SourceForge
Browse the Forums Development Blog
Support the project
Devoo Software
Powered by:

Source Forge Thanks Jetbrains for support us !! Thanks BB Software for support us !! TestDriven.NET Code Coverage by Clover.NET Code Project Article Larkware News Sharp Toolbox