Subscribe to The Madman Scribblings        RSS Feed
-----

New VB11 Features

Icon 7 Comments
New VB11 Features

A preview of some of the new features coming in VB11, which you can experiment with via the VS11 Developer Preview

The New Features
  • Async & Await
    This will be the major feature of VB11 asynchronous method supported directly by the language.
    Module Module1
      Sub Main
        Dim SourceCode = GetSourceCode()
        Console.WriteLine(SourceCode)
    
      End Sub
    
      Public Async Function GetSourceCode() As Task(Of String)
        Return Await (New Net.WebClient).DownloadStringTaskAsync("www.dreamincode.net")
       End Function
    End Module
    
    


    The infrastructure used in the Async & Await enables VB.net to have a Yield keyword like c#. This allows us to use Iterators.

  • Iterators
    You can implement Iterator various ways, through the use of the Yield keyword
    • Functions
        Public Iterator Function OneToHundred() As IEnumerable(Of Integer)
          For x = 1 To 100
            Yield x
          Next
        End Function
          
      

    • Lambdas
         Dim numbers_1_To_100 = Iterator Function()
                                   For x = 1 To 100
                                     Yield x
                                   Next
                                 End Function
          
      

    • Property (Strange but completes the list.)
        Public ReadOnly Iterator Property Strange() As IEnumerable(Of Integer)
          Get
            For x = 1 To 100
              Yield x
            Next
          End Get
        End Property
          
      

    • Iterator Lambdas (VB.net only)
        Dim numbers_1_To_100 = Iterator Function()
                                   For x = 1 To 100
                                     Yield x
                                   Next
                                 End Function
      


  • Namespace Global.
    Usually everything you write inside your project is enclosed inside a base namespace (typically the name of the project.) Sometime there situations where you need "escape" the behavior
    Namespace Global.Numbers
      <HideModuleName> Public Module Numbers
        Public Function Naturals() As IEnumerable(Of Integer)
          Return (Iterator Function()
                    Dim x = 0
                    While x < Integer.MaxValue
                      Threading.Interlocked.Increment(x)
                      Yield x
                    End While
                    Yield Integer.MaxValue
                  End Function)()
        End Function
      End Module
    
    End Namespace
    
    


    Which can, along side Iterators let me write a single function (above) the returns an IEnumerable containing the natural integer numbers (Whole Number starting from 1, up to the Integer.MaxValue)
    Imports Numbers
    Module Module1
    
      Sub Main()
        Dim Total = Naturals.Take(100).Where(Function(x) (x Mod 3) = 0 OrElse (x Mod 5 = 0)).Sum
      End Sub
    
    

7 Comments On This Entry

Page 1 of 1

Amrykid Icon

14 October 2011 - 07:00 AM
I'm looking forward to these features.
0

Tryparse Icon

14 October 2011 - 07:35 AM
Thanks for the preview ... I'm still waiting for our shop to upgrade to .Net 4 :whatsthat:
0

Yo! Icon

14 October 2011 - 12:46 PM
It's just a small thing but I like that they have the ribon control now ^^
0

Curtis Rutland Icon

14 October 2011 - 02:54 PM
I don't think Iterator Properties are all that strange. Properties are just fancy groups of specific methods. If there's such thing as an iterator method, why not an iterator property?
0

Yo! Icon

14 October 2011 - 09:37 PM
Sorry, I had read somewhere that the ribbon control was a new control added in but I just installed the Preview and noticed that it wasn't really there.
Sorry to mislead you. :stupid:
0

AdamSpeight2008 Icon

15 October 2011 - 09:55 AM
@Curtis Rutland: What I thought as strange was more concept of what it would mean to set an Iterator Property, Iterator are should on that fact you can Yield values from them, so in the Set what would be the equivalent of a yield?

In reality the Setter take in an IEnumerable(Of ?? ).
0

AdamSpeight2008 Icon

15 October 2011 - 09:55 AM
Like so
Public Class Tt
  Public Iterator Property W() As IEnumerable(Of Integer)
    Get
      Yield 1
    End Get
    Set(value As IEnumerable(Of Integer))

    End Set
  End Property
End Class
0
Page 1 of 1

Search My Blog

Recent Entries

Recent Comments