Thursday, July 07, 2005

Operator overloading in VB.NET

Finally VB (VS 2005) supports operator overloading.. See this article for a detailed overview

http://www.devx.com/codemag/Article/28267/1954?pf=true

Here is some example..

Public Class MyString
   Private _text As String
   Public Sub New(ByVal text As String)
      _text = text
   End Sub
   Property Text() As String
      Get
         Return _text
      End Get
      Set(ByVal value As String)
         _text = value
      End Set
   End Property
   Public Shared Operator -(ByVal str1 As MyString, _
      ByVal str2 As MyString) As String
      Return str1.Text.Substring _
         (0, str1.Text.Length - _
         str2.Text.Length) & str2.Text
   End Operator
End Class

Generics:

Generics is another new feature in the .NET 2.0 Framework. As such, languages such as C# and Visual Basic 2005 now support this new feature.

Using Generics, you can define a class definition without fixing the data type that it is using at design time. Generics are simply like template classes in C++. That is a great addition for our VB :)

No comments:

Articles - Design Patterns, Neural Networks, C#, Programming