How do you access the text value of the Dropdown UI?

Whenever the value is changed, I need to get the text as string and print it out. I have tried using the code below but it always returns null. Thank you in advance.

Note: code below is not C# but, now obsolete, JS-like Unity Script
var LocationPicker : GameObject;
var LocPickerString : String;

function Start ()
{
    LocPickerString = LocationPicker.GetComponent.<UI.Dropdown>().OptionData().text;
    Debug.Log(LocPickerString);
}

You can simply do this:

Debug.Log( Dropdown.options[Dropdown.value].text );

https://docs.unity3d.com/Packages/com.unity.ugui@1.0/api/UnityEngine.UI.Dropdown.html

I couldn’t get the above answers to work, so here is another (simpler) option for future readers:

//find your dropdown object
public Dropdown dropdownMenu;
  
//get the selected index
int menuIndex = dropdownMenu.value;
  
//get all options available within this dropdown menu
List<Dropdown.OptionData> menuOptions = dropdownMenu.options;
  
//get the string value of the selected index
string value = menuOptions[menuIndex].text;

Turns out that the selected value is always reflected real time in the Text component of a child of the Dropdown, which is the Label. So here is what I had done:

Note: code below is not C# but JS-like, now obsolete, Unity Script
var LocationPickerLabel : GameObject;
private var SelectedLocation : Text;
var LocName : String;

function Start ()
{
    SelectedLocation = LocationPickerLabel.GetComponent(UI.Text);
    LocName = SelectedLocation.text;
}

A little out of topic, but I can also set the value from the Start and therefore typing in an instruction before the drop down is pressed by typing SelectedLocation.text = "Any instruction that I need ..." in the start function.

Try:

locPickerString = LocationPicker.GetComponent<UI.Dropdown>().itemText.text

Dropdown documentation:

https://docs.unity3d.com/Packages/com.unity.ugui@1.0/api/UnityEngine.UI.Dropdown.html

The following will give you the text from the selected dropdown item:

Debug.Log( EventSystem.current.currentSelectedGameObject.name );

In most cases, you want to get the dropdown value on change. For this Unity recommends adding a listener. So here is an example:

[SerializeField] Dropdown dropDown;
  
void Start()
{
    // Add listener for when the value of the Dropdown changes, to take action
    dropDown.onValueChanged.AddListener(delegate { DropdownValueChanged(dropDown); });
}
  
// Display value of the dropdown on change
void DropdownValueChanged(Dropdown change)
{
    Debug.Log(dropDown.options[dropDown.value].text);
}