Changing textures?

Is there any way to change the texture that is being used by a material (mid game)?

This should do it:

renderer.material.mainTexture = anotherTexture;

Where anotherTexture is a Texture reference, e.g. a public Texture2D variable