I found a related post over on CodeThinked entitled “Ten C# Keywords That You Shouldn’t Be Using“.

He discusses several of the more obscure C# keywords and why they should be used only after careful review and understanding. I like all of them except the one on the keyword ref. I find at least one example of when to use it acceptable:

	static void DisposeOf<T>(ref T value) where T : IDisposable
	{
		if (value != null)
			value.Dispose();
		value = null;
	}

Though when using this approach I usually create the routine for a specific type rather than using a generic; however, it still holds to prove as a non-tragic use of ref.

Comments