material mat;
GetComponent<MeshRenderer> ().sharedMaterials [1] = mat;
Material[] mats = GetComponent<Renderer>().materials;
mats[1] = mat;
GetComponent<Renderer>().materials = mats;
First error: The class "Material" should be in capital letters. (your code shouldnt compile)
Second error:
GetComponent<MeshRenderer> ().sharedMaterials [1] = mat;
doesnt do anything.
You can not assign that material like this.
The rest of your code looks correct.
- Did you assign the "mat" in the inspector?
- Does your mesh even have more than 1 submesh?
- Do you even want to assign more than 1 material?
- Whats the error ? Doesnt it compile? Null reference? Nothing happenes?
- Does your mesh renderer get the materials or does it just look wrong in the 3d view?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MaterialArraySetter : MonoBehaviour {
public Material Material1;
void Start ()
{
Material[] materialsArray = GetComponent<Renderer>().materials;
materialsArray[1] = Material1;
GetComponent<Renderer>().materials = materialsArray;
}
}

EDIT2:
You seem to have compiler errors.

mats
array, setting its entry at a particular index, then assigning the modified array back to the renderer — this looks correct. Is it not performing the way you expect? If not, can you explain in detail what you want it to do, and what behaviour you're observing instead? \$\endgroup\$ – DMGregory♦ Feb 7 '19 at 13:29