How to Define a Linq Extension Method?

Extensions Methods are tricky in that they are not automatically picked up after you write one. You need either add a using directive or add a reference and then a using directive depending on where you put your extension method This is because extension methods are adding to a class, but not in the traditional way of say a partial class. You are extending the class, however, they are not really object-orientated, so it they require more work on your part before you can consume them, confused yet?

The following should help: using System.Linq. IQueryable personally I would divide them into a Namespace called "ExtensionMethods", and then further subdivide them into other Namespaces based on purpose, this will help your sanity There is no limit to the number of Namespaces you can nest, but there is a limit to how many static classes you can nest And in the code that calls it, once you hit the period, you should see it in the auto-complete list I will post an example if you need more help Example: Extensions. Cs using System; namespace Foo { namespace Bar { public static class RangeExtensions { public static string ToColumnLetter(this int col) { ... //universal notation for magic :) } } } } Usage.Cs using System; using Foo.

Bar; namespace Foo2 { public class Bar2 { public void ExtensionSample { Range range = .... Console. WriteLine(range.Column.ToColumnLetter()); } } } Cheers!

Extensions Methods are tricky in that they are not automatically picked up after you write one. You need either add a using directive or add a reference and then a using directive depending on where you put your extension method. This is because extension methods are adding to a class, but not in the traditional way of say a partial class.

You are extending the class, however, they are not really object-orientated, so it they require more work on your part before you can consume them, confused yet? The following should help: using System.Linq. IQueryable personally I would divide them into a Namespace called "ExtensionMethods", and then further subdivide them into other Namespaces based on purpose, this will help your sanity.

There is no limit to the number of Namespaces you can nest, but there is a limit to how many static classes you can nest. And in the code that calls it, once you hit the period, you should see it in the auto-complete list. I will post an example if you need more help.

Example: Extensions. Cs using System; namespace Foo { namespace Bar { public static class RangeExtensions { public static string ToColumnLetter(this int col) { ... //universal notation for magic :) } } } } Usage. Cs using System; using Foo.

Bar; namespace Foo2 { public class Bar2 { public void ExtensionSample { Range range = .... Console. WriteLine(range.Column.ToColumnLetter()); } } } Cheers!

Thanks a lot..mam – Luke101 Jan 12 '10 at 23:14.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions