Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Contents tagged with C#

  • Multiple Strongly Typed Partial Views in MVC

    Creating strongly typed views with the ASP.Net MVC framework is really easy, but what if you want to have multiple types on the same view? One way to achieve this is to create partial views for each type and creating a combined view model. Then the view will inherit this combined view model and each partial view will inherit from its component types.

  • LINQ Projection

    just recently I have been doing quite a bit of work with LINQ and L2S in particular. Although LINQ is nothing new now and I am sure the vast majority of readers out there have had some form of introduction to LINQ. However one of the great things that I still find fascinating is a technique called projection. This is a way to shape data coming back from a query into something more akin to what you want.

  • Why I prefer c# over VB

    A couple of weeks back I was asked by a friend of a friend why I code in c# over VB. I didn’t give him a very good answer at the time as I just couldn’t pinpoint the reason. Since then I have had a real good think about it and have come to this conclusion. It just looks bulky. Not a good reason I know. I am not what you would consider a power developer, I use .net for relatively simple tasks and there isn’t any feature I would consider using one language over the other. So for me it just comes down to aesthetics. I can and have programmed in both classic VB and VB.Net and it was only about 4 years ago that I decided to have a look at c#. Now when I look at old code I have written in VB.Net I not only shudder at the overall crapness of my code, but also the amount of non-whitespace. A simple while loop in VB looks less clean than its cousin in c#.

  • How do you test private methods?

    This morning I read a post by Davy Brion who was explaining a technique to test private methods. Although the post was interesting, it was a comment by Rafferty Uy that got me thinking. He suggests that you make your method protected instead of private and have the testing class inherit from this class. There is much debate as to whether you should be testing private methods at all, and as I am fairly new to unit testing, I have only ever tested my public methods.

  • Singleton in action

    I had one of those 'wow that's cool' moments last weekend. This sounds really sad and you may think that I need a life, but I was playing with the code for a basic singleton pattern found at:-

  • Zip up those bak files

    This is something I have come across during our SQL migration which I didn't even think about. You can zip up your bak files and save considerable hard drive space. We have a 14 gig database which happily compresses down to 2 gig. With hard drives coming down in price, you may think why bother. Well in our migration we have two separate domains for testing purposes which have to stay separate at all costs. Compressing our bak files we can burn it to DVD and move it to the test domain regularly for testing our in house applications.