how to get the name of a gameobject in unity code example

Example 1: unity scene name get

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GetSceneName : MonoBehavior {

	Scene m_Scene;
	string sceneName;

	private void Start() {
   		m_Scene = SceneManager.GetActiveScene();
   		sceneName = m_Scene.name;
 	}
}

Example 2: how to access gameobject name

// note how the 'g' is lowercase, when it's lowercase it accesses the GameObject its attached to
gameObject.name
// so if this script was attached an object named "Player", it will access "Player"

Example 3: how to name GameObject in c#

GameObject.name = "Ben";