Codeine .Net RSS 2.0
# Tuesday, 14 August 2007

For those of you that don’t know what FizzBuzz is, it became quite popular awhile back when Jeff Atwood posted to his blog a few quotes from people about interviewing candidates for programming jobs and the fact that many of them can’t code. (It’s possible that the topic originated from someone else.  I heard it originally from Scott Hanselman’s blog who referenced Jeff.)  FizzBuzz is a simple coding exercise where you write a loop that prints the numbers from 1 to 100, except if the number is divisible by three it outputs Fizz and if the number is divisible by five it outputs Buzz.  If it is divisible by both you output FizzBuzz.

What is an Extension Method?  An extension method is a new feature in .Net 3.5 that allows you to add methods to an existing object.  It allows you to modify an object without needing to create your own version of it through inheritance.  Why is this useful?  I’m sure there are many reasons.  One is that if you don’t have the ability to change the object that is being passed to your class then you can’t just use inheritance and create your own version of the object, but what you can do is create an extension method.

This example that I am going to walk you through will add a method to int called FizzBuzz.  Calling this method will output a string with either the number of your int, Fizz, Buzz, or FizzBuzz depending on the criteria stated above.

This code for the extension method is fairly simple:

 

namespace ExtensionMethodExample

{

    public static class CustomExtensionMethods

    {

        public static string FizzBuzz(this int value)

        {

            string rtnVal = "";

 

            if (value % 3 == 0)

            {

                rtnVal += "Fizz";

            }

 

            if (value % 5 == 0)

            {

                rtnVal += "Buzz";

            }

 

            if (rtnVal == "")

            {

                rtnVal = value.ToString();

            }

 

            return rtnVal;

 

        }

 

    }

}

 

Here I have a static class called CustomExtensionMethods. Next, I have created a static method called FizzBuzz.  The magic happens when I all this to the input parameter. I then calculate FizzBuzz on my input parameter and return the appropriate string.  (I’m sure there is a better way to implement FizzBuzz.)

That’s it.  I then utilitize the new FizzBuzz method like this(In my case I have created a simple console application):

using System;

using System.Collections.Generic;

using System.Text;

using ExtensionMethodExample;

 

namespace ExtenderMethodExample

{

    class Program

    {

        static void Main(string[] args)

        {

            for (int i = 1; i < 100; i++)

            {

                Console.WriteLine(i.FizzBuzz());

            }

 

            Console.ReadLine();

        }

    }

}

It’s that simple.  Drop this into a VS2008 console application and try it out.  You will have complete access to your extension methods via intellisense.  Happy coding.

 

Was this post helpful? Post a comment and let me know.

Tuesday, 14 August 2007 05:00:00 (Central Daylight Time, UTC-05:00)  #    Comments [0] - Trackback - Save to del.icio.us - Digg This! - Follow me on Twitter
Original Posts
# Friday, 10 August 2007

Well Greg Brill hasn’t responded to the email with my resume and I haven’t gotten any swag from DotNetRocks!, but you may have noticed that on episode #260 at five minutes and twenty seconds Richard Campbell read my email.  I was a little surprised myself as I was only half listening while I was at work, but sure enough he read my comments on show #244 with Scott Stanfield.  He didn’t read everything so here is my email in full:

 

Hey Guys,

I just wanted to let you know that the Scott Stanfield show was great.  I am a .Net developer and have been listening to the big three for some time now (.NetRocks, Hanselminutes, and Runas Radio).  My only complaint is that I need more content to listen to.  I’ve tried a few other podcasts, but either the content or the sound quality sucked and I removed them from my subscriptions.  After listening to the Scott Stanfield show I started thinking that you need to get this guy his own podcast.  He knew a wide range of topics and obviously enjoyed talking about them.   The way he presented information reminded me of Scott Hanselman as they both come across as very excited and enthusiastic about technology.  What do you think?  If you’re too busy to get it up and going then maybe you could hire a hot intern (or at least you could use it as an excuse to get one.)  Just thought I would throw that out there.  Keep up the good work.

 

Anyways, I’m going to officially start the campaign for the Scott Stanfield show.  I don’t know If Scott wants to do one or not, but if I can get enough people to ask then maybe he will.  My job is getting fairly boring and I need some interesting content to listen to so until I get a new job, some swag as a bribe to shut me up, or the Scott Stanfield show starts I’ll keep bugging for the new podcast.  I’ve put together a survey to gather everyone’s opinion about the idea so fill out the survey and feel free to comment about it here.

 

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

If you haven’t been watching Slashdot at all or any of the many MythTV forums out there then you don’t know that we will all soon be losing our free XML feed of TV listings.  Zap2it Labs originally provided the feed for free for noncommercial use, but they are going to stop providing this starting Sept 1st.  Several individuals organized and have worked with Zap2it to keep the feed going and have created a new entity called Schedule Direct.  Recently Schedule Direct reached an agreement with Zap2it to continue to provide the feed to open source DVR users through Schedule Direct.  Of course, the rub is that it is going to begin costing $5 a month to subscribe to.  According to the website they hope to turn this into only $20 a year, but they are waiting to figure out how many individuals sign up.

I don’t want to sound like a complete cheapo, but I can get a DVR from my cable company for $5 more a month, and the entire point of me originally building my own DVR was so that I would not have to pay a monthly fee and could instead use that money to keep adding to my DVR.  Also, I have no idea how many MythTV and XMLTV users are out there, but someone is bound to make a decent profit off of this at $5 a month per person.

A few of the guys at work, including myself think that this is an area that Google needs to get into.  Google’s all about providing different types of data, so why can’t they start providing TV data?  It seems like the exact kind of service that they would provide for free.  You could probably wrap some ads around it all and generate some very decent revenue.  I even considered doing it myself, but I already have two projects going on at the moment along with a full time job, and I didn’t think I could put together a solution quick enough for it to be beneficial.

Anyways, this leaves me with deciding what to do next and I am strongly considering switching my setup over to Windows Vista Home Premium and using the Media Center functionality.  From what I have heard it is pretty good, my only concern is if my hardware is all supported, which I can’t figured out without hunting down the details on everything, or just trying it out and killing my MythTV install.  Of course, after Sept 1st my DVR is just going to be a big paper weight anyways.  What do you think?  Should I not be a cheapo and pony up, or stick to my guns and have a completely monthly fee free DVR?

Friday, 10 August 2007 05:00:00 (Central Daylight Time, UTC-05:00)  #    Comments [3] - Trackback - Save to del.icio.us - Digg This! - Follow me on Twitter
Original Posts

Navigation
Archive
<2007 August>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678
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 2024
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 © 2024, David A. Osborn
DasBlog theme 'Business' created by Christoph De Baene (delarou)