Static/Shared Methods

I had been disappointed that when you use a CLR-based UDT, you didn’t have access to shared/static methods, only instance methods. In the zVarchar example, I thought it would be good to be able to use the following:

DECLARE @TextVar zVarchar

SELECT @TextVar.Compress(‘Some value           I       want        to          compress’)

This would be similar to how you’d use Decimal.Round() in the framework.

Well, Venkatesh (from MS) pointed out to me that you can. The shared/static methods are available via the older :: syntax directly off the class name. That’s the syntax that was used for all method calls in Beta 1. So you can do the following:

SELECT zVarChar::Compress(‘Some       value     I        want     to           compress’)

That’s even better as it doesn’t require an instantiation.

Leave a Reply

Your email address will not be published. Required fields are marked *