locked
VB.NET equivalent of C# default(T) RRS feed

  • Question

  • Hi,
       Is there any VB.NET equivalent of C# default(T)? If its not there how do I implement something in VB.NET which will be equivalent to default(T) of C#? Can anyone provide me with the source code for the same?

    Regards,
    Sandip
    Thursday, February 4, 2010 11:01 AM

Answers

  • C# "x is y" is equivalent to VB "TypeOf x Is y".
    C# "x = y as z" is equivalent to VB "x = TryCast(y, z)".

    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Friday, February 5, 2010 5:03 AM
  • Hi,

    check out this site: http://msmvps.com/blogs/bill/archive/2005/06/07/50897.aspx
    Hannes

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    • Marked as answer by sandip_ray63in Thursday, February 4, 2010 12:36 PM
    • Unmarked as answer by sandip_ray63in Friday, February 5, 2010 4:19 AM
    • Marked as answer by sandip_ray63in Friday, February 5, 2010 5:37 AM
    Thursday, February 4, 2010 11:24 AM
  • In VB, "Nothing" will work - this is because "Nothing" covers both reference type 'null' and value type defaults.
    C# needs "default" since it doesn't have a keyword which does this ("null" applies only to reference types).
    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Thursday, February 4, 2010 3:28 PM

All replies

  • Hi,

    check out this site: http://msmvps.com/blogs/bill/archive/2005/06/07/50897.aspx
    Hannes

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    • Marked as answer by sandip_ray63in Thursday, February 4, 2010 12:36 PM
    • Unmarked as answer by sandip_ray63in Friday, February 5, 2010 4:19 AM
    • Marked as answer by sandip_ray63in Friday, February 5, 2010 5:37 AM
    Thursday, February 4, 2010 11:24 AM
  • In VB, "Nothing" will work - this is because "Nothing" covers both reference type 'null' and value type defaults.
    C# needs "default" since it doesn't have a keyword which does this ("null" applies only to reference types).
    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Thursday, February 4, 2010 3:28 PM
  • Hi,
       Thanks to both of you(Heslacher and David) for your valuable answers. But I have one more query - what are the equivalents of C# "is" and "as" operators in VB.NET?

    Regards,
    Sandip
    Friday, February 5, 2010 4:36 AM
  • C# "x is y" is equivalent to VB "TypeOf x Is y".
    C# "x = y as z" is equivalent to VB "x = TryCast(y, z)".

    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Friday, February 5, 2010 5:03 AM
  • Thanks David for the valuable answer.

    Regards,
    Sandip
    Friday, February 5, 2010 6:03 AM