Codeine .Net RSS 2.0
# Thursday, 16 August 2007

Well I thought I would be nice and put up the code sample for implementing FizzBuzz using and extension method in VB.NET.  To read my full explanation of FizzBuzz and extension methods please read my previous post.

Those of you that know me, know that I could care less if you program in VB or C#, but I definitely prefer C# because it allows me to type a lot less.  Extension methods appear to be no different are a bit more complicated in VB, requiring that they are in a module and decorated with an attribute.

Module ExtensionMethods

    Sub Main()


        For i As Integer = 1 To 100
            Console.WriteLine(i.FizzBuzz)
        Next

        Console.ReadLine()

    End Sub

    <System.Runtime.CompilerServices.ExtensionAttribute()> _
Public Function FizzBuzz(ByVal Value As Integer) As String
        Dim rtnVal As String = ""

        If Value Mod 3 = 0 Then
            rtnVal += "Fizz"
        End If

        If Value Mod 5 = 0 Then
            rtnVal += "Buzz"
        End If

        If rtnVal = "" Then
            rtnVal = Value.ToString
        End If

        Return rtnVal
    End Function

End Module

Thursday, 16 August 2007 06:00:00 (Central Daylight Time, UTC-05:00)  #    Comments [0] - Trackback - Save to del.icio.us - Digg This! - Follow me on Twitter
Original Posts
Comments are closed.

Navigation
Archive
<2018 June>
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2018
David A. Osborn
Sign In
Statistics
Total Posts: 70
This Year: 0
This Month: 0
This Week: 0
Comments: 33
Themes
Pick a theme:
All Content © 2018, David A. Osborn
DasBlog theme 'Business' created by Christoph De Baene (delarou)