Problems using "new SpriteRenderer"

Here is my code:

        SpriteRenderer scrollTop = new SpriteRenderer();
		SpriteRenderer scrollBottom = new SpriteRenderer();
		scrollTop.enabled = true;
		scrollTop.sprite = scrollSprite;
		scrollTop.sortingLayerName = "Over GUI";
		scrollBottom.sprite = scrollSprite;
		scrollBottom.sortingLayerName = "Over GUI";

It is telling me I have a null reference exception. How do I go about creating a new sprite rendered in c#?

You can’t create instances of Component types because they cannot exist alone outside GameObjects. You always add them with AddComponent().

SpriteRenderer scrollTop = gameObject.AddComponent<SpriteRenderer>();

If you don’t have a GameObject to add to, you can create one and it will appear in the scene.

SpriteRenderer scrollTop = New GameObject("object name").AddComponent<SpriteRenderer>();