CSharpFeeds - All your C# feeds in one place.

Sponsors

Feed: Brendan Enrick

Site: http://brendan.enrick.com/ Link: http://feeds.feedburner.com/OrcsGoblinsAndDotNet

Friday, January 27, 2012

Foreach, IEnumerable, IEnumerator, and Duck Typing

by admin via Brendan Enrick on 1/27/2012 10:00:00 AM

During my Software Craftsmanship Precompiler session, I heard one of the students say, “all you need is an IEnumerable to use a foreach loop”. This sparked a bit of fun when I asked Steve Smith, my co-presenter, if that was correct. He confirmed that it was, and I disagreed. Being the scientists that we are, we decided to try it and see what happened. I of course knew that duck typing in C# should allow the Foreach loop to compile without anything having the method required by the IEnumerable in ...

[ read more ]

Friday, August 05, 2011

Overmocking

by admin via Brendan Enrick on 8/5/2011 1:28:09 PM

One of the most powerful tool available to developers testing a legacy code base is the ability to mock out classes that their code depends on. This is of great importance since our unit tests need to limit the scope, and we do this by trying to limit our dependencies. Through mocking we can exchange one dependency on the infrastructure of our application for an in-memory mock. Sometimes mocking is overused, and I am not just talking about cases where every objected gets mocked to the point whe ...

[ read more ]

Friday, July 15, 2011

Custom Model Binders in ASP.NET MVC

by Admin via Brendan Enrick on 7/15/2011 10:00:00 AM

In ASP.NET MVC, our system is built such that the interactions with the user are handled through Actions on our Controllers. We select our actions based on the route the user is using, which is a fancy way of saying that we base it on a pattern found in the URL they’re using. If we were on a page editing an object and we clicked the save button we would be sending the data to a URL somewhat like this one.   Notice that in our route that we have specified the name of the object that we’re ...

[ read more ]

Thursday, March 10, 2011

Go Try NuGet. Seriously.

by Admin via Brendan Enrick on 3/10/2011 9:32:00 AM

NuGet is best described as the tool from Microsoft that lets you add references to your project directly from the NuGet feed while storing and managing them locally. It lets you keep your references local to your source code, which will help you keep your software project encapsulated. When a package you use gets an update, you can ask NuGet to update your local version of the package. When telling people about NuGet it is important to explain how powerful it really is. NuGet is not just a ...

[ read more ]

Tuesday, February 22, 2011

IIS 7 Not Serving Static Files

by admin via Brendan Enrick on 2/22/2011 9:59:59 AM

I learned this potentially very useful bit of information from Scott Forsyth recently. As you may know, IIS 7 is modular, which allows for a great deal of control and customization of an IIS installation. There are a lot of other great benefits also. Web servers are great tools that allow us to put our content on the web. One of the most powerful things is their support for creating dynamic sites through different programming frameworks and languages. We sometimes take for granted our having sta ...

[ read more ]

Sunday, October 24, 2010

Wire up your ViewModels using a Service Locator

by admin via Brendan Enrick on 10/24/2010 2:57:34 PM

No MVVM solution is complete without having the DataContext bound to a ViewModel, but this wouldn’t be a fun development community if there were not some disagreement on the specifics of how to achieve certain goals. I will be recommending how I like to wire up ViewModels. There are other ways of doing this, but I will explain some of the reasons I use this method. You can start by building a View that needs to have certain traits in its ViewModel and then create a well-tested ViewModel separat ...

[ read more ]

Tuesday, October 12, 2010

Unit Testing With a Base Test Class

by admin via Brendan Enrick on 10/12/2010 11:51:13 AM

Writing good code that can be trusted to work means unit testing your code. In order to effectively maintain these tests you will need to follow the same principles you would with any other code. This of course means that you extract logic to achieve code reuse, name methods and objects clearly, use composition, and use inheritance. In this post I am going to show how you can get some code reuse when you’re following another good testing practice. You should keep things well abstracted. I like ...

[ read more ]

Friday, August 13, 2010

Using Dynamic Typing When an Interface was Needed

by benrick via Brendan Enrick on 8/13/2010 10:00:00 AM

Interfaces and base classes allow us a great deal of power in object oriented programming. We are able to accept a base type or interface and be given an implementation or an inheritor and continue working correctly. What if, however, we need to be able to accept more than one type, which have the same methods or properties, but to not share an interface or base class? Often the best answer is to add a common interface to these, so that the shared behavior is defined. In most of my cases when I ...

[ read more ]

Wednesday, May 26, 2010

Expect Unique Exceptions

by Brendan Enrick via Brendan Enrick on 5/26/2010 2:34:20 PM

One too common programming practice that irks me when I find it in source code is throwing or catching non-specific exceptions. I believe firmly that it is important to fail fast, and exceptions are a great way to ensure fast-failing code. If you drag out a failure you can hide the initial issue or allow a process to continue after an error has happened. Using non-specific exceptions will also hide information. Failing quickly is important as is being able to respond correctly to an exception an ...

[ read more ]

Expect Unique Exceptions

by benrick via Brendan Enrick on 5/26/2010 5:34:00 AM

One too common programming practice that irks me when I find it in source code is throwing or catching non-specific exceptions. I believe firmly that it is important to fail fast, and exceptions are a great way to ensure fast-failing code. If you drag out a failure you can hide the initial issue or allow a process to continue after an error has happened. Using non-specific exceptions will also hide information. Failing quickly is important as is being able to respond correctly to an exception an ...

[ read more ]

Tuesday, December 22, 2009

Silverlight Web Analytics: First Look

by Brendan Enrick via Brendan Enrick on 12/22/2009 2:00:00 PM

Anyone who has ever run a web site or a blog has probably taken a look at analytics packages to see who is visiting. I’ve recently been working on a very exciting project with Telerik, developing an application to provide this valuable information to bloggers and content creators. To get things started we decided to tackle some of the basics first by asking these few questions: “How many people are visiting my site?” “Which locations drive the most traffic to my ...

[ read more ]

Monday, November 23, 2009

A Quick Answer About Reference Types

by Brendan Enrick via Brendan Enrick on 11/23/2009 3:00:00 PM

Reference types were created to make dealing with pointers a little bit easier. They hide away the details of the pointers, so that the programmer need not think about them. In many ways I think they’re awesome, because they really achieve that goal. The problem is that by abstracting away the details of the pointers they’re sometimes difficult to work with, because they can be a little bit confusing. I received a comment about this topic on one of my ASP Alliance articles explaining value type ...

[ read more ]

Wednesday, October 28, 2009

Working with Interfaces – Practical Uses

by Brendan Enrick via Brendan Enrick on 10/28/2009 2:00:00 PM

Expanding on an article I wrote a couple of years ago where I explained interfaces in C#, I’d like to explain why people should use interfaces. I received an email from a reader of my ASP Alliance article. He understands how interfaces work, but he’s trying to see why so many people are raving wildly about their greatness. His questioning of them is great, because it really is not obvious why interfaces are useful. Anyone who says otherwise is just trying to brag. A couple of years ago, you ...

[ read more ]

Tuesday, October 27, 2009

Implementing IEnumerable and IEnumerator

by Brendan Enrick via Brendan Enrick on 10/27/2009 2:00:00 PM

Working with a foreach loop is the primary reason to implement the IEnumerable and IEnumerator interfaces. You’ll want one of each of these to work with the loop. I am going to do an example DateRange class which will implement IEnumerable<DateTime> and will allow us to iterate through a non-existent collection of DateTime objects. Note: I am aware of the fact that I could achieve the same result with a for loop. I find the foreach loop more readable. First we need to create a basic Da ...

[ read more ]

Wednesday, October 21, 2009

When Should You Comment You Code

by Brendan Enrick via Brendan Enrick on 10/21/2009 2:00:00 PM

When it is hard to understand or determine your intent, because your code is crap. Yep, that is pretty much the best time to comment your code. When I was in college I was told to make sure that I commented my code. I always wondered why. Now I know. Comments really tended to clutter things and make it less clear what I was trying to achieve. Comments take time to write, they take up valuable space, they add clutter, and they’re often out of date. So why do we write them? We write them because ...

[ read more ]

Wednesday, October 14, 2009

Null Reference Exception on Instance Methods

by Brendan Enrick via Brendan Enrick on 10/14/2009 3:00:00 PM

Recently I was reading through a bunch of interesting blog posts. I was looking for information about the use of callvirt in C#. Callvirt can be used to call both virtual and non-virtual methods, and in fact is how all methods are called in C#. I don’t know how much of a performance decrease there is based on this, but I doubt it is much of one. I stumbled across this interesting post covering why C# uses callvirt from Eric Gunnerson’s blog. We had gotten a report from somebody (likely one o ...

[ read more ]

Monday, September 28, 2009

Transactional Data Persistence with OpenAccess

by Brendan Enrick via Brendan Enrick on 9/28/2009 3:30:00 PM

OpenAccess is an Object Relational Mapper (ORM) from Telerik, and as you might have noticed from my earlier post about building an OpenAccess enabled project on a build server, I am currently working with OpenAccess on one of my projects. I figure that since I am using this Object Relational Mapper that I should post regularly about using it so that others starting to use OpenAccess have a shorter learning curve. Making modifications to persisted data needs to be done transactionally so that an ...

[ read more ]

Wednesday, September 23, 2009

Fun With Web Forms Controls and LINQ

by Brendan Enrick via Brendan Enrick on 9/23/2009 2:00:00 PM

Since LINQ has come out I’ve been very fascinated with it. LINQ to SQL is kind of cool, but working with in-memory collections is my favorite. Sure anything we can do with LINQ we could have done before, but now it’s easy. While not exactly the most practical and certainly not the most efficient method of handling things, working with a page’s Controls collection can be a lot of fun. So perhaps I want to change the text of all of the TextBoxes on a page. I can easily grab that collection like ...

[ read more ]

Tuesday, September 22, 2009

Your IoC Container is Showing

by Brendan Enrick via Brendan Enrick on 9/22/2009 2:00:00 PM

Learning to keep things about your application hidden is important. Your code should be exposed to as few things as possible. Using tools like Ninject, Structuremap, etc. is great, but you should try to keep them at arm’s length. If you want to keep your Inversion of Control (IoC) container hidden you can put a nice wrapper around it. In an application I am currently working with I started by using an IoC container that was very simple. Just enough so that I didn’t have to use the poor man’s d ...

[ read more ]

Friday, September 18, 2009

Overloading Implicit Conversions with Generics in C#

by Brendan Enrick via Brendan Enrick on 9/18/2009 2:00:00 PM

Overloading operators in a language is an excellent tool in every developer’s tool belt. It allows us to design our code in ways feeling far more natural. For example if we didn’t implement operator overloading for addition of numbers we would have some strange code. Could you imagine if we still wrote this kind of stuff? int x = 5; int y = 4; int z = x.Add(y); When we teach addition the non-computer way we learn it as “5 + 4 = 9”. The language reverses things and we swit ...

[ read more ]

Thursday, August 06, 2009

Constructors Should Be Simple and Stupid

by Brendan Enrick via Brendan Enrick on 8/6/2009 3:00:00 PM

There are plenty of commonly known and upheld ideas about how software should be written. There are rules and guidelines professed by many developers which recommend following this design principle or that one. Some are more important than others. Some are easier to find and correct than others. One such rule that I believe is important to follow is that all constructors remain simple and stupid. This is about as advanced as I believe a constructor should even be. public SomeObject(int someVal ...

[ read more ]

Monday, June 22, 2009

Overusing var in C#

by Brendan Enrick via Brendan Enrick on 6/22/2009 2:00:00 PM

With C# 3.0 came one new feature I both love and hate; the implicitly typed local variable: var. I think it is great because it is implicitly typed, but it is still strongly typed. At compile time it will be the explicit type as if you had typed the actual type name. Visual Studio is able to determine during development what the type is, so there isn't much of a downside. However, I believe it gets overused. I think it is great if the line contains the "new" keyword, because I can alre ...

[ read more ]

Monday, June 08, 2009

Daily Dev Speedup - Using Visual Studio Snippets

by Brendan Enrick via Brendan Enrick on 6/8/2009 1:00:00 PM

In Visual Studio there are code snippets which can be used with auto-completion. These are a lot of the common structures used by developers when writing code. They are customizable using Visual Studio, but I find it much easier to use editors like Snippy. So if you were not using snippets because one of them was not exactly the way you wanted it to be, give a snippet editor a shot. I highly recommend creating your own snippets as well as customizing them. I for example use one to create tests. ...

[ read more ]

Friday, May 22, 2009

Time-Tested Testing Tips - Part 4

by Brendan Enrick via Brendan Enrick on 5/22/2009 6:20:00 PM

Rather than spending the time with needless introduction, I think I’ll just jump right in today. I’ve got a few tips I am going to post today. Reproduce Bugs Using Unit Tests Yes, this is another test driven development method. When you’re looking for a bug, it is very common to try to reproduce it. What you might try to do instead of doing this is reproduce the bug manually, fix the bug, and then write a test to prevent it. Well I think that is a pretty bad way of doing things ...

[ read more ]

Time-Tested Testing Tips - Part 3

by Brendan Enrick via Brendan Enrick on 5/22/2009 2:00:00 PM

Context switching is very costly and this same issue can be seen when writing tests, but I would argue most importantly in maintaining and reading tests. Time-Tested Testing Tips - Part 1 Time-Tested Testing Tips - Part 2 There are three main parts to a test. The first part sets everything up, the second part takes some action, and the third part expects certain results given the the start and the action taken. In this tip I'll be talking about the first part, the setup. Keep Test-Rel ...

[ read more ]

Wednesday, May 20, 2009

Choosing A Dependency Injection Pattern

by Brendan Enrick via Brendan Enrick on 5/20/2009 3:00:26 PM

There are a few patterns you can follow when writing code which injects dependencies; constructor, property, and method injection. Which way is the best one to use? I don't really know for certain, but I can talk a little bit about the differences and some of the benefits of each. I am sure this behaves as most situations do with certain ones perform better in certain situations. Constructor Injection In this form of injection we pass the dependency into the object using its constructor. Before ...

[ read more ]

Monday, April 13, 2009

LINQ Your Collections with IEqualityComparer and Lambda Expressions

by Brendan Enrick via Brendan Enrick on 4/13/2009 5:50:00 PM

Anyone using LINQ to manipulate in-memory collections is probably also using plenty of lambda expressions to make things quite easy. These two additions were really meant for each other. One of our interns here recently ran into an interesting problem while using LINQ. As a relatively new user of .NET based languages, reference types caused him a bit of trouble. The problem While using the dot notation with lambda expressions, he was using the Except method in the following way. List<MyObje ...

[ read more ]

Friday, March 06, 2009

Just In Time Properties

by Brendan Enrick via Brendan Enrick on 3/6/2009 4:00:00 PM

Properties with backing fields can easily be null. I often see properties which check the backing field to see if it is null. This is commonly done with an if statement with one line of initialization. One way to get around this is to use the coalescing operator in C#. If we use this in combination with an expressions, which might be a method, we are able to easily handle this property with one line. Here is an example of what I am talking about. private SomeType _someObject; public SomeType So ...

[ read more ]

Thursday, March 05, 2009

Getting Around a Lack of Interfaces With Partial Classes

by Brendan Enrick via Brendan Enrick on 3/5/2009 9:58:54 PM

One pain point which comes along often when working with others' libraries are the classes that are not open and implementing interfaces. A lot of the classes we developers use every day implement no interfaces. Since the class is out of my control, I obviously cannot give it an interface, so I need some other way to work with it. This creates a problem when we need to mock out the class. There are ways in which we can get around this though. Wrapping Classes In my opinion, the most dependable ...

[ read more ]

Friday, January 30, 2009

Converting an Array of Integers int[] to an Array of Strings string[]

by Brendan Enrick via Brendan Enrick on 1/30/2009 4:00:00 PM

I was working on a code snippet I plan to put into a blog post, and while writing it I needed to convert and array of integers to an array of strings. I try to think of a quick easy way to do this and none comes to mind. Well, I of course know that I could just loop through them and convert them from ints to strings, but that is really lame especially when I want the code to be small so I can put it in a blog post. So there are a few options that present themselves when you are looking for a met ...

[ read more ]

Tuesday, January 27, 2009

Parameter Order Should Be Consistent

by Brendan Enrick via Brendan Enrick on 1/27/2009 6:10:57 PM

I was looking at a piece of code recently and noticed that someone was checking for a null parameter and throwing an ArgumentException, so I figured since ArgumentNullException inherits from ArgumentException I would just replace it with the more specific exception. Little did I know that Microsoft has a wee little bit of a problem with consistency on these. With ArgumentExceptions it is important to have a message as well as specify which parameter is causing the trouble, so there are 2 string ...

[ read more ]

Parameter Order Should Be Consistent

by Brendan Enrick via Brendan Enrick on 1/27/2009 6:10:57 PM

I was looking at a piece of code recently and noticed that someone was checking for a null parameter and throwing an ArgumentException, so I figured since ArgumentNullException inherits from ArgumentException I would just replace it with the more specific exception. Little did I know that Microsoft has a wee little bit of a problem with consistency on these. With ArgumentExceptions it is important to have a message as well as specify which parameter is causing the trouble, so there are 2 string ...

[ read more ]

Wednesday, January 21, 2009

Validating Entity objects

by Brendan Enrick via Brendan Enrick on 1/21/2009 7:22:58 PM

While working with an entity object I wanted to validate, I took some time to do some Googling. I was planning on creating an IValidator<T> interface so I could keep the validation separate from my classes, and I was going to implement this interface for every entity that needed it. Since validation is pretty common I figured I would take a look around first to see if there were some good ways of performing validation which differed slightly from how I had done things previously or offered ...

[ read more ]

Validating Entity objects

by Brendan Enrick via Brendan Enrick on 1/21/2009 7:22:58 PM

While working with an entity object I wanted to validate, I took some time to do some Googling. I was planning on creating an IValidator<T> interface so I could keep the validation separate from my classes, and I was going to implement this interface for every entity that needed it. Since validation is pretty common I figured I would take a look around first to see if there were some good ways of performing validation which differed slightly from how I had done things previously or offered ...

[ read more ]

Validating Entity objects

by Brendan Enrick via Brendan Enrick on 1/21/2009 7:22:58 PM

While working with an entity object I wanted to validate, I took some time to do some Googling. I was planning on creating an IValidator<T> interface so I could keep the validation separate from my classes, and I was going to implement this interface for every entity that needed it. Since validation is pretty common I figured I would take a look around first to see if there were some good ways of performing validation which differed slightly from how I had done things previously or offered ...

[ read more ]

Wednesday, January 14, 2009

Write a Test Before Fixing a Bug

by Brendan Enrick via Brendan Enrick on 1/14/2009 4:00:13 PM

As I've said in previous posts, it is important to write tests for your code. A lot of the time I am talking about when refactoring code or when writing new code. Now I agree that bug fixing could be considered refactoring, but people seem to treat it differently. When fixing bugs they want to go in and quickly make the bug go away. That is a dangerous way to solve things, because it doesn't prevent the bug from returning. If a bug exists in your system then there are test cases missing from the ...

[ read more ]

Write a Test Before Fixing a Bug

by Brendan Enrick via Brendan Enrick on 1/14/2009 4:00:13 PM

As I've said in previous posts, it is important to write tests for your code. A lot of the time I am talking about when refactoring code or when writing new code. Now I agree that bug fixing could be considered refactoring, but people seem to treat it differently. When fixing bugs they want to go in and quickly make the bug go away. That is a dangerous way to solve things, because it doesn't prevent the bug from returning. If a bug exists in your system then there are test cases missing from the ...

[ read more ]

Friday, December 19, 2008

Comparing Nullable DateTimes

by Brendan Enrick via Brendan Enrick on 12/19/2008 2:52:00 PM

A couple of days ago I was working on some code when I noticed a comparisons of two DateTime? variables. So I wondered what would happen if either or both of those variables had gotten null values. Since I had never tried it before I figured I would just take a couple of minutes and test some things. Since I already had visual studio open I just created a unit test and wrote some code in there to test the behavior. I've not done it in a console application since it is easier for most people to u ...

[ read more ]

Comparing Nullable DateTimes

by Brendan Enrick via Brendan Enrick on 12/19/2008 2:52:00 PM

A couple of days ago I was working on some code when I noticed a comparisons of two DateTime? variables. So I wondered what would happen if either or both of those variables had gotten null values. Since I had never tried it before I figured I would just take a couple of minutes and test some things. Since I already had visual studio open I just created a unit test and wrote some code in there to test the behavior. I've not done it in a console application since it is easier for most people to u ...

[ read more ]

Thursday, December 04, 2008

One Reason to Test Before Creating a Method

by Brendan Enrick via Brendan Enrick on 12/4/2008 4:00:32 PM

Most people who know about Test Driven Development have heard the phrase, "Red, Green, Refactor". When it comes to actual implementation of this technique there seems to be a bit of a disagreement. By following the rules of RGR we all agree that we start by writing a failing test (Red), we write the code to make the test pass (Green), and then we make the code better and remove duplication (Refactor). The point of contention I hear about most often is in the Red stage. Some people say to write t ...

[ read more ]

Tuesday, December 02, 2008

Testing Private Methods

by Brendan Enrick via Brendan Enrick on 12/2/2008 11:07:19 PM

In a previous post about cutting large classes down in size I mentioned that Sometimes there are methods kept private in a class. Some calculations are kept private because nothing should be calling those methods on this class. This is a good hint that the method belongs somewhere else. If the method is kept private because it doesn't make sense for a user of this class to use it, it belongs somewhere else. Private methods are a common occurrence in classes. Sometimes they should be moved into ...

[ read more ]

Thursday, November 27, 2008

Beginning Unit Testing

by via Brendan Enrick on 11/27/2008 3:21:51 AM

Getting started unit testing is a difficult task. I've seen plenty of people learning to unit test and it took some time for me and seems to take some time for everyone before unit testing really clicks. Part of the reason why unit testing is difficult for people to get started with is that the code most developers write is not testable. Yes, not only is it important to test, but it is important for your code to be testable. Most code is so difficult to test that anyone who doesn't know how to u ...

[ read more ]

Wednesday, November 26, 2008

Keeping Large Classes in Line

by Brendan Enrick via Brendan Enrick on 11/26/2008 3:52:27 AM

One thing that seems to get out of control quickly on a lot of projects I've seen is a tendency for classes to grow to enormous size. This is one problem that seems to turn up at least once in a lot of projects. Why does it happen? Because programmers are lazy. Yes, I said it. We are. I think it is a good thing in a lot of cases. We are "efficiency experts". We pay an up-front cost writing a program so we will have less work to do to solve a problem. By writing the code we save ourselves time. T ...

[ read more ]

Saturday, November 22, 2008

Breaking Down Customer Stories

by Brendan Enrick via Brendan Enrick on 11/22/2008 6:28:28 PM

Creating stories to work on is an integral task in agile software development. These stories are what the team of developers will be working on for the iteration. Where do the stories come from? Well, through discussion with the development team, the customer says what he wants. What types of stories does the customer ask for most of the time? The customer asks for epics. What makes them epics? They're just too large. When writing software in an agile manner it is important to have very small pi ...

[ read more ]

Returning From Inside a Using Statement

by via Brendan Enrick on 11/22/2008 4:59:00 AM

A while back I wrote a blog post regarding this topic. In that post I explain that it is safe to use a return statement inside a using block, because the using block will handle the disposing of the defined IDisposable object. This is one truly great ability of the IDisposable interface. It makes it very important to use in my opinion. The using block in combination is very nice, because it handles the disposal for you. One of my commenter on that post asked me if I was certain that the return s ...

[ read more ]

Wednesday, November 19, 2008

Code Coverage Is Not Enough

by Brendan Enrick via Brendan Enrick on 11/19/2008 3:55:19 PM

When people write tests there is one metric I hear them mention quite often. Yes, you guessed it. Code coverage is mentioned by many people when talking about how well their code is tested. I believe this is a very useful metric, but as the title of this post states, code coverage is not enough. When testing code it is important to try to check all cases which are likely to be able to produce different results. Odd and interesting cases are important. Tests should be written to handle different ...

[ read more ]

Monday, October 27, 2008

Optional and Named Parameters in C#.... Finally

by Brendan via Brendan Enrick on 10/27/2008 9:37:56 PM

I've used Python a decent amount in the past. I enjoy the language and I've taught the language to non-computer science students at Kent State University. There are plenty of things that I really love about that language. I could write plenty of blog posts regarding how totally awesome python is. I tend to use it for quick little bits of code. I don't use too much Python for production code, but I do like a lot of the language features. One of the big pieces of Python I enjoy is the ability to d ...

[ read more ]

Dynamically Typed Objects in C#

by Brendan via Brendan Enrick on 10/27/2008 9:28:55 PM

In the past the C# language obtained a new feature allowing it to declare variables as type "var". It didn't really do any dynamic typing though. For the most part the var is just there for developer convenience. Some people have complained about this in the past. Stating that C# 3.0 doesn't have dynamic types. The problem is that with that it is figuring out when compiling what type the variable is. I am currently sitting in the Los Angeles Convention Center for the PDC 2008. I am watching a se ...

[ read more ]

Thursday, August 28, 2008

Nested Using Statements

by Brendan via Brendan Enrick on 8/28/2008 6:50:43 PM

I think it is a great idea to always be reading code. You may learn more than you intend to sometimes. Read an article to learn one trick and you may learn a completely different one. Earlier today I was reading some code written by Steve Smith. He wrote an extension method for the System.Web.UI.Control class called RenderControl. I was just looking to see what he had written, and from this little snippet of code I learned a cool trick.   public static string RenderControl(this System.We ...

[ read more ]

Thursday, May 22, 2008

Visual Studio Keyboard Shortcuts Disabled in Code Snippets

by via Brendan Enrick on 5/22/2008 8:10:00 PM

Since Visual Studio 2008 came out I've been extremely impressed with the software. One shortcut which I believe probably exists in CodeRush and Resharper is the ability to find the using directive needed at any given time. in VS2008 you can press ctrl + . and a little menu will appear which will add using directives for you. This makes writing code so much easier, because I don't have to go to the top of my file to add using statements. I type the name of what I need, press ctrl + . and keep goi ...

[ read more ]

Return Within a C# Using Statement

by Brendan via Brendan Enrick on 5/22/2008 1:38:25 PM

While writing some code earlier today I needed to return from within a using statement. Doing these sorts of things always makes me appreciate the using statement and how wonderful it really is, so I decided to write about it here. As many of you know the using statement in C# is a good tool for managing types which will be accessing unmanaged resources. Some examples of these are SqlConnections, FileReaders, and plenty of other similar types. The key to these is that they all implement the IDis ...

[ read more ]

Tuesday, May 20, 2008

Differences Between Structures and Classes in C#

by Brendan via Brendan Enrick on 5/20/2008 1:37:09 PM

Earlier today I was looking for a good reference outlining the differences between structs and classes in C#. I wanted a refresher on the subject, because I've been doing a reasonable amount of teaching lately. At Lake Quincy Media we have hired a couple of developers currently in school. In bringing them up to speed, I've been explaining a lot about programming languages, paradigms, etc. and it is nice to have good references to make sure that I am not passing along misinformation. In my quest ...

[ read more ]

Wednesday, January 30, 2008

C# Generics vs C++ Templates

by Brendan via Brendan Enrick on 1/30/2008 2:44:19 PM

I regularly meet with a group of my college friends with whom I studied Computer Science. While at a great local bar we have plenty of interesting computer-related conversations. A lot of .NET developers probably spend most of their time discussing technical topics with other .NET developers. Our conversations are much more interesting because everyone there works with different languages and different types of technology. It really adds a lot to our discussions. So as has happened a few times, ...

[ read more ]

Friday, January 18, 2008

Try Catch Performance in CSharp: A Simple Test Response

by Brendan via Brendan Enrick on 1/18/2008 2:57:50 PM

I read an interesting little post about a Try Except Performance Test Using Python written by Patrick Altman. As he mentioned, I have also had discussions with people about this exact topic in the past plenty of times. He was testing the performance issue of whether it is better to use a try catch block to handle possible errors or to check for them before they're a problem. He handled 2 different cases; the success and the failure. Using loops he performed time checks on these to see how long ...

[ read more ]

Friday, January 04, 2008

Explicitly and Implicitly Implementing Interfaces

by Brendan via Brendan Enrick on 1/4/2008 9:26:29 PM

I read an interesting blog post from Joydip Kanjilal where he described an interesting little trick with interfaces. I, being a bit of a fan of interfaces, read the post and thought I'd throw my $0.02 in also. I couldn't pass up an opportunity to talk about interfaces. He first shows simply how to create an interface and how to implement the interface implicitly. The difference between implicitly and explicitly writing this code is what creates the different circumstances Joydip shows in his dem ...

[ read more ]

Thursday, December 13, 2007

Static Methods and Interfaces in C#

by Brendan via Brendan Enrick on 12/13/2007 2:39:16 PM

Someone just commented on my C# interfaces article on ASP Alliance asking an interesting question, and I figure I will respond to it here since I can give a better response here. I don't want to clutter the article comments. Also I can add nifty cool pictures, format all of my text nicely, and write a heck of a lot more here. This is the excellent question I was asked. All my classes implementing my interface should have a static funtion.Why can't I have a static function in an interface??? -J ...

[ read more ]

Tuesday, December 04, 2007

Using the as Statement to Cast Without Exceptions in C#

by Brendan via Brendan Enrick on 12/4/2007 2:58:05 AM

It is common to obtain variables with a type which is not the desired one. Considering that plenty of times there will be variables passed using the object data type, it is important to be able to cast your variables into more usable types. Say for example you're passed a variable as an object. You probably want to be able to access properties or methods of this object, so you will need to cast it into another class. The simple way of doing this is to use code similar to this.DataTable myData = ...

[ read more ]

Thursday, November 29, 2007

Knowing the Default Access Modifiers in C#

by Brendan via Brendan Enrick on 11/29/2007 7:21:04 PM

I have a few friends in college who are learning C# on the side. I've been answering their questions when they ask. One interesting question was regarding access modifiers. I was asked which access modifiers are used by default in certain situations when there is not one specified. First I'll quickly remind everyone of the access modifiers and what has permission to access them. private - Any members of the same class have access. protected - Any members of the same class or any derived class h ...

[ read more ]

Sunday, November 11, 2007

Memory Management: Generics vs objects

by Brendan via Brendan Enrick on 11/11/2007 8:15:00 PM

One of the most important parts of software development is memory management. Memory management is important for every software application. If one is to write a well developed software application, one must have a fair bit of knowledge in the area of memory managament. It is important to understand the underlying technology which allows programs to function. There are many aspects of programs which come into play often in .NET applications; variables, functions, garbage collection.Understa ...

[ read more ]

Wednesday, October 10, 2007

Understanding the Queue Data Structure Using a Simple C# Implementation

by Brendan via Brendan Enrick on 10/10/2007 6:34:12 PM

Introduction The Queue is a very important and common Data Structure in Computer Science. As the name queue suggests, this data structure can be described with an analogy of waiting in a line. There is no cutting allowed in the line, so the first person in the line is the first person out of the line. With the data structure it is the same way First In First Out (FIFO). The best way of managing the data in a queue in my opinion is by storing the data in a "circle" by this I mean that ...

[ read more ]

Tuesday, October 09, 2007

Simple C# Stack Implementation

by Brendan via Brendan Enrick on 10/9/2007 2:27:13 PM

I've just written a quick little stack implementation for use in explaining the stack data structure. It is written in C# and is not exactly a robust solution, but it works well enough. It is stubbed out with the basics of what is required to have a working stack. If you don't know how a Stack works, I also recommend reading my Simple Explanation of the Stack Data Structure. For the heck of it, since I love Generics, I decided to make this a Generic Stack. The first step is to create the Generic ...

[ read more ]

Thursday, August 02, 2007

Generic List AddRange, Remove, and Count Performance

by Brendan via Brendan Enrick on 8/2/2007 1:00:00 PM

The .NET System.Collections.Generic.List class is not a linked list as non-.NET users might expect. This list class is actually more like an array list than a linked list. Because of this it has some of the benefits of arrays. Simply because of the array data structure which exists within the generic list class, the class is able to achieve a constant time Count function. The basic array data structure is a collection of objects which are stored contiguously in memory, and because of this it mak ...

[ read more ]

Thursday, July 26, 2007

Great C# to VB and VB to C# Converters

by Brendan via Brendan Enrick on 7/26/2007 2:29:00 PM

I was recently on Developer Fusion when I noticed some simple and easy to use C# to VB and VB to C# converters. It is not difficult to translate code from one language to the other, but sometimes I'll want to test out a code snippet from some site and it is in VB. I use C# and I don't want to have to sit there translating 20 lines of code, and I also don't want to go and get an expensive converter. These seem to do a reasonable job converting between the two languages. I've used ...

[ read more ]

Thursday, May 31, 2007

Simple Lazy Loading

by Brendan via Brendan Enrick on 5/31/2007 3:06:00 PM

Lately, I’ve noticed a lot of people who are not careful about how they load objects. Managing objects is a fundamentally important part of software development. Lets say for example I have an integer in the query string, and I need to use this number in a few places on my page. Well it is obviously inefficient and an ugly process to check the query string and parse the value into an integer every time I want to access that number. I could also at the beginning just grab the number, but th ...

[ read more ]

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us