Extension Methods
There are 5 entries for the tag
Extension Methods
I have somewhat mixed feelings towards enums in C#. On the one hand, they can greatly improve readability of your code, but on the other hand, they are not much more than textual masks on numeric values. You can't inherit from them, you can't use enum as generic constraint (for which I see no good reason), and you can't extend them... Or can you? With the addition of Extension Methods in C# 3.0 you finally have the tools to put some life in them. Consider you have an enum like this:public enum Mp3Player
{
IPodClassic,
...
Let's look at an example: This is somewhat simplified diagram of classes that are part of object model I created for a certain XML format (it doesn't reflect physical structure of XML file, rather it's a conceptual, higher level model). Document can contain few types of elements. To achieve this, it has a method Add, that takes a ValueElement (which is an abstract class). The problem here, is that it is not obvious what is a ValueElement. You have to know what you can put into Add method, which means, you have to know what ValueElement's children are. Their...
You can call extension methods on null elements. It's obvious when you think about it: its a normal static method where you specify its first parameter with this. using System;namespace ExtensionMethods2{ class Program { static void Main(string[] args) { string isNull = null; Console.WriteLine(isNull.IsNullOrEmpty()); string isNotNull =...
I decided that it's about time to familiarize myself with new features of .NET 3.5 and C# 3.0. And I don't mean see an overview, because I've read many times about what's new in it, and I have basic understanding of all those new goodies that new version of framework/language brings. What I mean by familiarize is understand thoroughly and that is what this "Hello World" series (hopefully) is (hopefully) about.
I'm gonna start with extension methods as this is what I've started playing with already, and then... well we'll see :)
Extension Methods are a completely new concept to OOP world (at least...
LINQ is great. It's what everyone has been talking about for some time now, and it's the biggest thing that comes with .NET 3.5. But I guess that those saying that with time, people will appreciate other new things in C# 3.0/VB9.0 were right. I'm not even sure that LINQ will be THE feature I'm gonna use the most. For some time now, in my spare time I've been working on a project that I'm going to publish up on codeplex. I know that I've chosen the wrong order here (first, created site for project, then started talking about it,...