Static/Shared Methods

Published Sat, Dec 11 2004 12:29 | GregLow

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.