Change image for gameobject via code only

I have a gameobject and source images already added to Unity “imageA, imageB”. How can I change the image of gameobject?

The already existed solution doesn’t work for me, e.g. preload these images “image A”&“image B” from inspector as public variables. The problem is that I have about 40 gameobjects which need to have their image sources change from time to time. I simple can’t predefine 40 images in advance.

How can I access to the “UNITY/images/imageA.png”, “UNITY/images/imageB.png” so I can use them later as texture2D?

SOLUTION:
gameObject.GetComponent().sprite = Resources.Load(“Images/custom_image_name”);

NOTE: Folder “Images” should be located in folder “Resources” otherwise it won’t work.